Repository navigation
fix(router): drop the reload id when a fetcher action is aborted mid-revalidation - #15365
Merged
brophdawg11 merged 3 commits intoAug 3, 2026
Merged
Conversation
…revalidation `handleFetcherAction` records a `fetchReloadIds` entry once the action resolves and post-action revalidation begins, and deletes it when that revalidation completes. The aborted bail-out sits one line above that delete, so any abort landing in the window leaves the entry behind. An aborted fetcher then goes idle and is pruned from `state.fetchers` by `updateState`, which for a still-mounted fetcher uses a bare Map delete that skips the auxiliary maps. The next `abortStaleFetchLoads` or `markFetchersDone` caller iterates `fetchReloadIds`, finds the orphaned key, and throws `Expected fetcher: <key>`. It surfaces as an unhandled rejection, so no error boundary catches it and the in-flight navigation dies. Moving the delete above the bail-out covers every abort path at once. `fetchControllers` needs no equivalent change: `abortFetcher` deletes from it as part of aborting, so it is self-cleaning on this path, which is why the original code could skip it on the early return. `fetchReloadIds` has no such path — its only other deletion site is `deleteFetcher`. That asymmetry is the bug. The non-aborted path is unchanged: there is no `await` between the line's old and new position, only the `if` test and a `removeEventListener`, neither of which reads `fetchReloadIds`. Adds two tests, both failing before this change: - `submit()` then `load()` on the same key, with no `reset()` involved - `reset()` during post-action revalidation
afairbrother
force-pushed
the
af-fetch-reload-ids-abort
branch
from
August 3, 2026 13:41
142b7d9 to
44de9d3
Compare
brophdawg11
reviewed
Aug 3, 2026
Comment on lines
2954
to
2961
| // Drop this before the aborted bail-out below. An aborted fetcher goes | ||
| // idle and is pruned from state.fetchers, and abortStaleFetchLoads | ||
| // invariants on a fetcher existing for every key still in fetchReloadIds | ||
| fetchReloadIds.delete(key); | ||
|
|
||
| if (abortController.signal.aborted) { | ||
| return; | ||
| } |
Contributor
There was a problem hiding this comment.
I think there may be a scenario where a second fetcher.submit overtakes a in-flight slow reload and we don't want to blindly delete here since we'd be deleting the newer reload id. I think we may want to leave the existing deletion in place and just add a conditional deletion to the aborted path:
Suggested change
| // Drop this before the aborted bail-out below. An aborted fetcher goes | |
| // idle and is pruned from state.fetchers, and abortStaleFetchLoads | |
| // invariants on a fetcher existing for every key still in fetchReloadIds | |
| fetchReloadIds.delete(key); | |
| if (abortController.signal.aborted) { | |
| return; | |
| } | |
| if (abortController.signal.aborted) { | |
| // Drop this before the aborted bail-out below. An aborted fetcher goes | |
| // idle and is pruned from state.fetchers, and abortStaleFetchLoads | |
| // invariants on a fetcher existing for every key still in fetchReloadIds | |
| if (fetchReloadIds.get(key) === loadId) { | |
| fetchReloadIds.delete(key); | |
| } | |
| return; | |
| } |
Clarified the issue with `handleFetcherAction` and its handling of aborted fetchers, which led to unhandled rejections during navigation.
Contributor
✅ CLA SignedThanks for signing the Contributor License Agreement. |
Contributor
✅ Change File FoundOne or more change files found.
|
Merged
ginabak
reviewed
Aug 4, 2026
| - adil62 | ||
| - adriananin | ||
| - adrienharnay | ||
| - afairbrother |
Contributor
|
🤖 Hello there, We recently published version Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
handleFetcherActionreturns early on an aborted signal one line above its ownfetchReloadIds.delete(key), so an abort landing between "action resolved" and "revalidation loaders settled" leaves the reload id behind:The aborted fetcher then goes idle, and
updateStateprunes idle mounted fetchers fromstate.fetcherswith a barestate.fetchers.delete(key)that doesn't touch the aux maps. The next call intoabortStaleFetchLoads— ormarkFetchersDone/markFetchRedirectsDone— iteratesfetchReloadIds, finds the stale key, and throwsinvariant(fetcher, "Expected fetcher: " + key).It throws out of a promise chain, so no error boundary catches it. It surfaces as an unhandled rejection and the in-flight navigation dies.
Reproduction
Ordinary usage, no
unstable_APIs — either of:fetcher.submit()thenfetcher.load()on the same key while the submission's revalidation is in flightfetcher.reset()during that same windowThose two are asymmetric, which is the useful detail. A resubmit is safe: it re-enters
handleFetcherAction, which overwrites the same key and cleans it up on its own completion. Aload()goes throughhandleFetcherLoader, which never touchesfetchReloadIds— so nothing collects the orphan the aborted action left behind.fetchControllersdoesn't have this problem becauseabortFetcherdeletes from it as part of aborting;fetchReloadIdshas no equivalent self-cleaning path, and that asymmetry is the bug.Found on 7.15.1, via a fetcher reset landing during a post-save navigation. The relevant code is byte-identical on 7.18.2 and 8.3.0.
The fix
Hoist
fetchReloadIds.delete(key)above the aborted bail-out. One line moved — it covers every path that can abort during post-action revalidation, rather than hardening each reader individually.Two tests in
__tests__/router/fetchers-test.ts, one per repro above. Both fail onmainwithExpected fetcher: keyand pass with the change.One point for review
There's precedent for fixing this from the reader side instead — #12049 / #12050 / #12054 dropped the
invariantinabortStaleFetchLoadsfor the siblingExpected fetch controllererror. The equivalent here would be to skip keys with no fetcher and delete the entry on the miss.I went with the writer side because the stale entry is the defect itself, and this stops it being created rather than tolerating it at three read sites. Happy to switch if you'd rather the two stayed consistent.