-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
✅ Deploy Preview for kitbag-router ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@stackoverfloweth incorporated the feedback from our sync review. I think this one is ready to go |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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
I don't get a build error when I build locally. What are you seeing?
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. |
There was a problem hiding this 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 🎉
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 withRegisteredRouterPush
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.