Skip to content

Commit cec6186

Browse files
authored
don't include fetcher submision on navigation in fetch action redirect (#10225)
1 parent b162e81 commit cec6186

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

packages/router/__tests__/router-test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8702,8 +8702,18 @@ describe("a router", () => {
87028702
expect(A.fetcher.state).toBe("submitting");
87038703
let AR = await A.actions.foo.redirect("/bar");
87048704
expect(A.fetcher.state).toBe("loading");
8705-
expect(t.router.state.navigation.state).toBe("loading");
8706-
expect(t.router.state.navigation.location?.pathname).toBe("/bar");
8705+
expect(t.router.state.navigation).toMatchObject({
8706+
state: "loading",
8707+
location: {
8708+
pathname: "/bar",
8709+
},
8710+
// Fetcher action redirect should not proxy the fetcher submission
8711+
// onto the loading navigation
8712+
formAction: undefined,
8713+
formData: undefined,
8714+
formEncType: undefined,
8715+
formMethod: undefined,
8716+
});
87078717
await AR.loaders.root.resolve("ROOT*");
87088718
await AR.loaders.bar.resolve("stuff");
87098719
expect(A.fetcher).toEqual({

packages/router/router.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ export function createRouter(init: RouterInit): Router {
11521152
location: Location,
11531153
opts?: {
11541154
submission?: Submission;
1155+
fetcherSubmission?: Submission;
11551156
overrideNavigation?: Navigation;
11561157
pendingError?: ErrorResponse;
11571158
startUninterruptedRevalidation?: boolean;
@@ -1263,6 +1264,7 @@ export function createRouter(init: RouterInit): Router {
12631264
matches,
12641265
loadingNavigation,
12651266
opts && opts.submission,
1267+
opts && opts.fetcherSubmission,
12661268
opts && opts.replace,
12671269
pendingActionData,
12681270
pendingError
@@ -1385,6 +1387,7 @@ export function createRouter(init: RouterInit): Router {
13851387
matches: AgnosticDataRouteMatch[],
13861388
overrideNavigation?: Navigation,
13871389
submission?: Submission,
1390+
fetcherSubmission?: Submission,
13881391
replace?: boolean,
13891392
pendingActionData?: RouteData,
13901393
pendingError?: RouteData
@@ -1406,19 +1409,20 @@ export function createRouter(init: RouterInit): Router {
14061409

14071410
// If this was a redirect from an action we don't have a "submission" but
14081411
// we have it on the loading navigation so use that if available
1409-
let activeSubmission = submission
1410-
? submission
1411-
: loadingNavigation.formMethod &&
1412-
loadingNavigation.formAction &&
1413-
loadingNavigation.formData &&
1414-
loadingNavigation.formEncType
1415-
? {
1416-
formMethod: loadingNavigation.formMethod,
1417-
formAction: loadingNavigation.formAction,
1418-
formData: loadingNavigation.formData,
1419-
formEncType: loadingNavigation.formEncType,
1420-
}
1421-
: undefined;
1412+
let activeSubmission =
1413+
submission || fetcherSubmission
1414+
? submission || fetcherSubmission
1415+
: loadingNavigation.formMethod &&
1416+
loadingNavigation.formAction &&
1417+
loadingNavigation.formData &&
1418+
loadingNavigation.formEncType
1419+
? {
1420+
formMethod: loadingNavigation.formMethod,
1421+
formAction: loadingNavigation.formAction,
1422+
formData: loadingNavigation.formData,
1423+
formEncType: loadingNavigation.formEncType,
1424+
}
1425+
: undefined;
14221426

14231427
let routesToUse = inFlightDataRoutes || dataRoutes;
14241428
let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(
@@ -2053,6 +2057,22 @@ export function createRouter(init: RouterInit): Router {
20532057
// Preserve this flag across redirects
20542058
preventScrollReset: pendingPreventScrollReset,
20552059
});
2060+
} else if (isFetchActionRedirect) {
2061+
// For a fetch action redirect, we kick off a new loading navigation
2062+
// without the fetcher submission, but we send it along for shouldRevalidate
2063+
await startNavigation(redirectHistoryAction, redirectLocation, {
2064+
overrideNavigation: {
2065+
state: "loading",
2066+
location: redirectLocation,
2067+
formMethod: undefined,
2068+
formAction: undefined,
2069+
formEncType: undefined,
2070+
formData: undefined,
2071+
},
2072+
fetcherSubmission: submission,
2073+
// Preserve this flag across redirects
2074+
preventScrollReset: pendingPreventScrollReset,
2075+
});
20562076
} else {
20572077
// Otherwise, we kick off a new loading navigation, preserving the
20582078
// submission info for the duration of this navigation

0 commit comments

Comments
 (0)