Repository navigation
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 |
| type FetchersContextObject = Map<string, any>; | ||
|
|
||
| const FetchersContext = React.createContext<FetchersContextObject | null>(null); | ||
| const FetchersContext = React.createContext<FetchersContextObject>(new Map()); |
There was a problem hiding this comment.
The ref counting now lives in the router so this fetchers context just holds the data
| { unstable_viewTransitionOpts: viewTransitionOpts } | ||
| { deletedFetchers, unstable_viewTransitionOpts: viewTransitionOpts } | ||
| ) => { | ||
| deletedFetchers.forEach((key) => fetcherData.current.delete(key)); |
There was a problem hiding this comment.
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.
No longer ref counting via the context
|
🤖 Hello there, We just published version Thanks! |
|
🤖 Hello there, We just published version Thanks! |
When
v7_fetcherPersistis 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