Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor callback context and handling #328

Merged
merged 8 commits into from
Nov 29, 2024
Merged

Conversation

pleek91
Copy link
Contributor

@pleek91 pleek91 commented Nov 26, 2024

Description

Not a change to routing behavior. But abstracts the callback context for hooks into something more generic so we can use it for props. Half of this is copied from #276 which is getting pretty outdated because main has changed quite a bit due to prefetching.

I've removed the generic from hook runners which was used for typing push. But that wasn't really accomplishing anything. So I replaced it with RegisteredRouterPush from the callback context utility.

I also moved the hook response types to be more generic callback response types and wrote a generic handler in createRouter. There are some special cases for before hooks which are handled separately but before and after hooks and in the next PR props can all share the same callback response handler.

Copy link

netlify bot commented Nov 26, 2024

Deploy Preview for kitbag-router ready!

Name Link
🔨 Latest commit e868f0c
🔍 Latest deploy log https://app.netlify.com/sites/kitbag-router/deploys/6748bba664b06200082cdcc9
😎 Deploy Preview https://deploy-preview-328--kitbag-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pleek91
Copy link
Contributor Author

pleek91 commented Nov 28, 2024

@stackoverfloweth incorporated the feedback from our sync review. I think this one is ready to go

Copy link
Contributor

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get build error locally on this branch, do you see that?

this doesn't quite fully implement my suggestion of a shared instanceof check. Take a look at this PR

/**
* Defines the structure of a callback response.
*/
export type CallbackResponse = CallbackSuccessResponse | CallbackPushResponse | CallbackRejectResponse | CallbackAbortResponse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this type isn't used anywhere, will this be used in props context?

Copy link
Contributor

@stackoverfloweth stackoverfloweth Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use versions of this in my suggestion PR

#331

Copy link
Contributor

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought I'd share the possibility, but don't feel strongly. Happy to merge as is

@pleek91
Copy link
Contributor Author

pleek91 commented Nov 28, 2024

I get build error locally on this branch, do you see that?

I don't get a build error when I build locally. What are you seeing?

his doesn't quite fully implement my suggestion of a shared instanceof check. Take a look at #331

I went down this route too. But since the two places that use context currently have different context I thought it might be best to allow each callback to pick and choose its context and handle what its expecting. Especially once we add props now there are three different things that have context. Each of which could be different. So it seemed simpler to make the callback context agnostic of where/how it was used.

Copy link
Contributor

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error I was seeing was probably just an outdated dependency, not having the issue anymore 🎉

@pleek91 pleek91 merged commit e68163a into main Nov 29, 2024
6 checks passed
@pleek91 pleek91 deleted the refactor-callback-context branch November 29, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants