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
5 changes: 5 additions & 0 deletions .changeset/nice-planets-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

[REMOVE] Fix additional edge case for #10674
48 changes: 48 additions & 0 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10073,6 +10073,54 @@ describe("a router", () => {
expect(t.router.state.fetchers.get(key)?.state).toBe("idle");
expect(t.router.state.fetchers.get(key)?.data).toBeUndefined();
});

it("ignores submission redirect navigation if preceded by a normal GET navigation (w/o loaders)", async () => {
let key = "key";
let t = setup({
routes: [
{
path: "",
id: "root",
children: [
{
path: "/",
id: "index",
},
{
path: "/foo",
id: "foo",
action: true,
},
{
path: "/bar",
id: "bar",
},
{
path: "/baz",
id: "baz",
},
],
},
],
});
let A = await t.fetch("/foo", key, {
formMethod: "post",
formData: createFormData({ key: "value" }),
});
await t.navigate("/bar");

// This redirect should be ignored
await A.actions.foo.redirect("/baz");
expect(t.router.state.fetchers.get(key)?.state).toBe("idle");

expect(t.router.state).toMatchObject({
navigation: IDLE_NAVIGATION,
location: { pathname: "/bar" },
loaderData: {},
});
expect(t.router.state.fetchers.get(key)?.state).toBe("idle");
expect(t.router.state.fetchers.get(key)?.data).toBeUndefined();
});
});

describe(`
Expand Down
3 changes: 2 additions & 1 deletion packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,8 @@ export function createRouter(init: RouterInit): Router {
(matchesToLoad && matchesToLoad.some((m) => m.route.id === routeId))
);

pendingNavigationLoadId = ++incrementingLoadId;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a fresh "load" even if there are no loaders to run


// Short circuit if we have no loaders to run
if (matchesToLoad.length === 0 && revalidatingFetchers.length === 0) {
let updatedFetchers = markFetchRedirectsDone();
Expand Down Expand Up @@ -1541,7 +1543,6 @@ export function createRouter(init: RouterInit): Router {
});
}

pendingNavigationLoadId = ++incrementingLoadId;
revalidatingFetchers.forEach((rf) => {
if (fetchControllers.has(rf.key)) {
abortFetcher(rf.key);
Expand Down