Skip to content

Commit 3f75db4

Browse files
authored
Fix edge case for fetcher redirect abort when no loaders exist (#10709)
1 parent 3cda182 commit 3f75db4

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

.changeset/nice-planets-fly.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
[REMOVE] Fix additional edge case for #10674

packages/router/__tests__/router-test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10073,6 +10073,54 @@ describe("a router", () => {
1007310073
expect(t.router.state.fetchers.get(key)?.state).toBe("idle");
1007410074
expect(t.router.state.fetchers.get(key)?.data).toBeUndefined();
1007510075
});
10076+
10077+
it("ignores submission redirect navigation if preceded by a normal GET navigation (w/o loaders)", async () => {
10078+
let key = "key";
10079+
let t = setup({
10080+
routes: [
10081+
{
10082+
path: "",
10083+
id: "root",
10084+
children: [
10085+
{
10086+
path: "/",
10087+
id: "index",
10088+
},
10089+
{
10090+
path: "/foo",
10091+
id: "foo",
10092+
action: true,
10093+
},
10094+
{
10095+
path: "/bar",
10096+
id: "bar",
10097+
},
10098+
{
10099+
path: "/baz",
10100+
id: "baz",
10101+
},
10102+
],
10103+
},
10104+
],
10105+
});
10106+
let A = await t.fetch("/foo", key, {
10107+
formMethod: "post",
10108+
formData: createFormData({ key: "value" }),
10109+
});
10110+
await t.navigate("/bar");
10111+
10112+
// This redirect should be ignored
10113+
await A.actions.foo.redirect("/baz");
10114+
expect(t.router.state.fetchers.get(key)?.state).toBe("idle");
10115+
10116+
expect(t.router.state).toMatchObject({
10117+
navigation: IDLE_NAVIGATION,
10118+
location: { pathname: "/bar" },
10119+
loaderData: {},
10120+
});
10121+
expect(t.router.state.fetchers.get(key)?.state).toBe("idle");
10122+
expect(t.router.state.fetchers.get(key)?.data).toBeUndefined();
10123+
});
1007610124
});
1007710125

1007810126
describe(`

packages/router/router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,8 @@ export function createRouter(init: RouterInit): Router {
15001500
(matchesToLoad && matchesToLoad.some((m) => m.route.id === routeId))
15011501
);
15021502

1503+
pendingNavigationLoadId = ++incrementingLoadId;
1504+
15031505
// Short circuit if we have no loaders to run
15041506
if (matchesToLoad.length === 0 && revalidatingFetchers.length === 0) {
15051507
let updatedFetchers = markFetchRedirectsDone();
@@ -1541,7 +1543,6 @@ export function createRouter(init: RouterInit): Router {
15411543
});
15421544
}
15431545

1544-
pendingNavigationLoadId = ++incrementingLoadId;
15451546
revalidatingFetchers.forEach((rf) => {
15461547
if (fetchControllers.has(rf.key)) {
15471548
abortFetcher(rf.key);

0 commit comments

Comments
 (0)