Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deduplicate-lock-file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
token: ${{ secrets.FORMAT_PAT }}

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
uses: actions/setup-node@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
ref: ${{ github.event.inputs.branch }}

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
uses: actions/setup-node@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
token: ${{ secrets.FORMAT_PAT }}

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
uses: actions/setup-node@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@v7

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
uses: actions/setup-node@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:

- name: Setup pnpm
if: steps.changed-files.outputs.mode == 'run'
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
if: steps.changed-files.outputs.mode == 'run'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
ref: ${{ inputs.baseBranch }}

- name: Install pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Install Node.js
uses: actions/setup-node@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-comments-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
uses: actions/setup-node@v6
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
token: ${{ secrets.FORMAT_PAT }}

- name: Install pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Install Node.js
uses: actions/setup-node@v6
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
uses: actions/checkout@v7

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
uses: actions/setup-node@v6
Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
uses: actions/setup-node@v6
Expand Down Expand Up @@ -184,7 +184,7 @@ jobs:
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
uses: actions/setup-node@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-integration-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/checkout@v7

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node ${{ inputs.node_version }}
uses: actions/setup-node@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
uses: actions/checkout@v7

- name: Setup pnpm
uses: pnpm/action-setup@v6
uses: pnpm/action-setup@v6.0.9

- name: Setup node
uses: actions/setup-node@v6
Expand Down
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- adil62
- adriananin
- adrienharnay
- afairbrother
- afzalsayed96
- AhmadMayo
- Ajayff4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `Expected fetcher: <key>` error thrown on navigation when a fetcher is aborted during its post-action revalidation
100 changes: 100 additions & 0 deletions packages/react-router/__tests__/router/fetchers-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3704,6 +3704,106 @@ describe("fetchers", () => {
});
});

describe("fetchReloadIds cleanup", () => {
it("does not strand a reload id when a load supersedes a submission on the same key", async () => {
let t = initializeTest();
let key = "key";

let A = await t.fetch("/foo", key, {
formMethod: "post",
formData: createFormData({ key: "value" }),
});
expect(t.fetchers[key].state).toBe("submitting");

await A.actions.foo.resolve("ACTION");
expect(t.fetchers[key]).toMatchObject({
formMethod: "POST",
formAction: "/foo",
state: "loading",
data: "ACTION",
});

let B = await t.fetch("/foo", key);
expect(t.fetchers[key]).toMatchObject({
formMethod: undefined,
formAction: undefined,
state: "loading",
data: "ACTION",
});

await A.loaders.root.resolve("ROOT*");
await A.loaders.index.resolve("INDEX*");
await B.loaders.foo.resolve("FOO");
expect(t.fetchers[key]).toMatchObject({
formMethod: undefined,
formAction: undefined,
state: "idle",
data: "FOO",
});

// idle fetchers are pruned from state.fetchers
expect(t.router.state.fetchers.has(key)).toBe(false);

let C = await t.navigate("/bar");
await C.loaders.root.resolve("ROOT**");
await C.loaders.bar.resolve("BAR");
expect(t.router.state).toMatchObject({
location: { pathname: "/bar" },
navigation: { state: "idle" },
loaderData: {
root: "ROOT**",
bar: "BAR",
},
});
});

it("does not strand a reload id when a fetcher is reset during post-action revalidation", async () => {
let t = initializeTest();
let key = "key";

let A = await t.fetch("/foo", key, {
formMethod: "post",
formData: createFormData({ key: "value" }),
});
expect(t.fetchers[key]).toMatchObject({
formMethod: "POST",
formAction: "/foo",
state: "submitting",
data: undefined,
});

await A.actions.foo.resolve("ACTION");
expect(t.fetchers[key]).toMatchObject({
formMethod: "POST",
formAction: "/foo",
state: "loading",
data: "ACTION",
});

t.router.resetFetcher(key);
expect(t.fetchers[key]).toMatchObject({
state: "idle",
data: null,
});
expect(t.router.state.fetchers.has(key)).toBe(false);

await A.loaders.root.resolve("ROOT*");
await A.loaders.index.resolve("INDEX*");

let B = await t.navigate("/bar");
await B.loaders.root.resolve("ROOT**");
await B.loaders.bar.resolve("BAR");
expect(t.router.state).toMatchObject({
location: { pathname: "/bar" },
navigation: { state: "idle" },
loaderData: {
root: "ROOT**",
bar: "BAR",
},
});
});
});

describe("fetcher Map mutation", () => {
// The root cause of the bug: after updateState({ fetchers: new Map(...) })
// hands a Map (MapA) to React, a subsequent direct mutation of
Expand Down
6 changes: 6 additions & 0 deletions packages/react-router/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,12 @@ export function createRouter(init: RouterInit): Router {
);

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;
}

Expand Down