-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Allow persisted fetchers unmounted during submit to revalidate #11102
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@remix-run/router": patch | ||
--- | ||
|
||
Fix bug preventing revalidation from occuring for persisted fetchers unmounted during the `submitting` phase |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1981,33 +1981,39 @@ export function createRouter(init: RouterInit): Router { | |
return; | ||
} | ||
|
||
if (deletedFetchers.has(key)) { | ||
updateFetcherState(key, getDoneFetcher(undefined)); | ||
return; | ||
} | ||
Comment on lines
-1984
to
-1987
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was too aggressive. It works for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Easiest to see the changes with whitespace ignored |
||
|
||
if (isRedirectResult(actionResult)) { | ||
fetchControllers.delete(key); | ||
if (pendingNavigationLoadId > originatingLoadId) { | ||
// A new navigation was kicked off after our action started, so that | ||
// should take precedence over this redirect navigation. We already | ||
// set isRevalidationRequired so all loaders for the new route should | ||
// fire unless opted out via shouldRevalidate | ||
// When using v7_fetcherPersist, we don't want errors bubbling up to the UI | ||
// or redirects processed for unmounted fetchers so we just revert them to | ||
// idle | ||
if (future.v7_fetcherPersist && deletedFetchers.has(key)) { | ||
if (isRedirectResult(actionResult) || isErrorResult(actionResult)) { | ||
updateFetcherState(key, getDoneFetcher(undefined)); | ||
return; | ||
} else { | ||
fetchRedirectIds.add(key); | ||
updateFetcherState(key, getLoadingFetcher(submission)); | ||
return startRedirectNavigation(state, actionResult, { | ||
fetcherSubmission: submission, | ||
}); | ||
} | ||
} | ||
// Let SuccessResult's fall through for revalidation | ||
} else { | ||
if (isRedirectResult(actionResult)) { | ||
fetchControllers.delete(key); | ||
if (pendingNavigationLoadId > originatingLoadId) { | ||
// A new navigation was kicked off after our action started, so that | ||
// should take precedence over this redirect navigation. We already | ||
// set isRevalidationRequired so all loaders for the new route should | ||
// fire unless opted out via shouldRevalidate | ||
updateFetcherState(key, getDoneFetcher(undefined)); | ||
return; | ||
} else { | ||
fetchRedirectIds.add(key); | ||
updateFetcherState(key, getLoadingFetcher(submission)); | ||
return startRedirectNavigation(state, actionResult, { | ||
fetcherSubmission: submission, | ||
}); | ||
} | ||
} | ||
|
||
// Process any non-redirect errors thrown | ||
if (isErrorResult(actionResult)) { | ||
setFetcherError(key, routeId, actionResult.error); | ||
return; | ||
// Process any non-redirect errors thrown | ||
if (isErrorResult(actionResult)) { | ||
setFetcherError(key, routeId, actionResult.error); | ||
return; | ||
} | ||
} | ||
|
||
if (isDeferredResult(actionResult)) { | ||
|
@@ -2237,6 +2243,8 @@ export function createRouter(init: RouterInit): Router { | |
return; | ||
} | ||
|
||
// We don't want errors bubbling up or redirects followed for unmounted | ||
// fetchers, so short circuit here if it was removed from the UI | ||
if (deletedFetchers.has(key)) { | ||
updateFetcherState(key, getDoneFetcher(undefined)); | ||
return; | ||
|
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.
This test was incorrect before due to the bug. The revalidation would cause the count to increment again after the navigation completed