-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Add fetcher data layer #10961
Add fetcher data layer #10961
Conversation
🦋 Changeset detectedLatest commit: a9c1886 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
type FetchersContextObject = { | ||
fetcherData: Map<string, any>; | ||
register: (key: string) => void; | ||
unregister: (key: string) => void; | ||
}; |
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.
Fetcher data lives in the React layer now, and we use ref counting via register
/unregister
to know when to remove from fetcherData
@@ -457,6 +472,12 @@ export function RouterProvider({ | |||
newState: RouterState, | |||
{ unstable_viewTransitionOpts: viewTransitionOpts } | |||
) => { | |||
newState.fetchers.forEach((fetcher, key) => { | |||
if (fetcher.data !== undefined) { | |||
fetcherData.current.set(key, fetcher.data); |
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.
Fetcher data hand-off from the router to the React data layer
@@ -1216,6 +1241,49 @@ function useDataRouterState(hookName: DataRouterStateHook) { | |||
return state; | |||
} | |||
|
|||
function useFetcherDataLayer() { | |||
let fetcherRefs = React.useRef<Map<string, number>>(new Map()); | |||
let fetcherData = React.useRef<Map<string, any>>(new Map()); |
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 we're OK using a ref here but I need to bang on some edge cases to be sure - all tests and such pass as-is which is reassuring. The idea is that anytime a fetcher.data
needs to update - a fetcher will have changed state
which will be what triggers the re-render, and we don't need useState
version of fetcherData
.
5a17ffe
to
2c6b70a
Compare
9ca6ef8
to
d3adf5e
Compare
d3adf5e
to
a9c1886
Compare
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
Dependent on #10960
Adds a fetcher data layer to
RouterProvider
to setup the 3rd (and final) PR for this work (a future flag to change the fetcher cleanup/persistence behavior)