Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: Multiple consecutive redirects not handled consistently between navigations and fetchers
51 changes: 51 additions & 0 deletions packages/react-router/__tests__/router/should-revalidate-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions packages/react-router/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down