-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Updates for v7_fetcherPersist post-processing logic #10977
Updates for v7_fetcherPersist post-processing logic #10977
Conversation
🦋 Changeset detectedLatest commit: 7a29035 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
|
||
const FetchersContext = React.createContext<FetchersContextObject | null>(null); | ||
const FetchersContext = React.createContext<FetchersContextObject>(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.
The ref counting now lives in the router so this fetchers context just holds the data
) => { | ||
deletedFetchers.forEach((key) => fetcherData.current.delete(key)); |
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.
The router tells us which fetchers can be deleted (once their ref counts go to 0)
let registerFetcher = React.useCallback( | ||
(key: string) => { | ||
let count = fetcherRefs.current.get(key); | ||
if (count == null) { | ||
fetcherRefs.current.set(key, 1); | ||
} else { | ||
fetcherRefs.current.set(key, count + 1); | ||
} | ||
}, | ||
[fetcherRefs] | ||
); | ||
|
||
let unregisterFetcher = React.useCallback( | ||
(key: string) => { | ||
let count = fetcherRefs.current.get(key); | ||
if (count == null || count <= 1) { | ||
fetcherRefs.current.delete(key); | ||
fetcherData.current.delete(key); | ||
} else { | ||
fetcherRefs.current.set(key, count - 1); | ||
} | ||
}, | ||
[fetcherData, fetcherRefs] | ||
); |
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.
No longer ref counting via the context
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
When
v7_fetcherPersist
is enabled we open up some new code flows for fetcher result processing that we need to consider.if (request.signal.aborted)
We do this by lifting the ref counting up into the router so it knows if any instances of a given fetcher key are still mounted in the UI.
useFetcher({ key })
, then we do process the result