From d5f1394a4916ceb892fb6bc9f8c03a92189a5ce9 Mon Sep 17 00:00:00 2001 From: Yogesh Kadam Date: Tue, 28 Jul 2026 21:01:24 +0530 Subject: [PATCH 1/2] fix: Multiple consecutive redirects not handled consistently between navigations and fetchers #14450 --- .../router/should-revalidate-test.ts | 51 +++++++++++++++++++ packages/react-router/lib/router/router.ts | 1 + 2 files changed, 52 insertions(+) diff --git a/packages/react-router/__tests__/router/should-revalidate-test.ts b/packages/react-router/__tests__/router/should-revalidate-test.ts index 575c73f8ec..146b848d63 100644 --- a/packages/react-router/__tests__/router/should-revalidate-test.ts +++ b/packages/react-router/__tests__/router/should-revalidate-test.ts @@ -783,6 +783,57 @@ describe("shouldRevalidate", () => { router.dispose(); }); + it("applies shouldRevalidate after consecutive redirects from a fetcher submission", async () => { + let shouldRevalidate = jest.fn((args) => true); + + let history = createMemoryHistory({ initialEntries: ["/landing"] }); + let router = createRouter({ + history, + routes: [ + { + path: "", + id: "root", + loader: () => "ROOT", + shouldRevalidate, + children: [ + { + path: "/landing", + id: "landing", + loader: () => "LANDING", + }, + { + path: "/", + id: "index", + loader: () => redirect("/landing"), + }, + { + path: "/form", + id: "form", + action: () => redirect("/"), + }, + ], + }, + ], + }); + + router.initialize(); + await tick(); + + let key = "key"; + router.fetch(key, "root", "/form", { + formMethod: "post", + formData: createFormData({}), + }); + + await tick(); + + expect(shouldRevalidate).toHaveBeenCalledTimes(2); + expect(shouldRevalidate.mock.calls[0][0].formMethod).toBe("POST"); + expect(shouldRevalidate.mock.calls[1][0].formMethod).toBe("POST"); + + router.dispose(); + }); + it("preserves non-revalidated loaderData on navigations", async () => { let count = 0; let history = createMemoryHistory(); diff --git a/packages/react-router/lib/router/router.ts b/packages/react-router/lib/router/router.ts index 1a56d58f1b..d2c9ef6bce 100644 --- a/packages/react-router/lib/router/router.ts +++ b/packages/react-router/lib/router/router.ts @@ -2516,6 +2516,7 @@ export function createRouter(init: RouterInit): Router { let redirect = findRedirect(loaderResults); if (redirect) { await startRedirectNavigation(request, redirect.result, true, { + fetcherSubmission: activeSubmission, replace, }); return { shortCircuited: true }; From 984cc3df973dcf3b4b3e6d1a7fe81d10d20c6eda Mon Sep 17 00:00:00 2001 From: Yogesh Kadam Date: Tue, 11 Aug 2026 20:57:17 +0530 Subject: [PATCH 2/2] patch: add change file --- .../patch.fix-multiple-consecutive-redirects-not-handled.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/react-router/.changes/patch.fix-multiple-consecutive-redirects-not-handled.md diff --git a/packages/react-router/.changes/patch.fix-multiple-consecutive-redirects-not-handled.md b/packages/react-router/.changes/patch.fix-multiple-consecutive-redirects-not-handled.md new file mode 100644 index 0000000000..9deee928a2 --- /dev/null +++ b/packages/react-router/.changes/patch.fix-multiple-consecutive-redirects-not-handled.md @@ -0,0 +1 @@ +fix: Multiple consecutive redirects not handled consistently between navigations and fetchers