Skip to content

Commit 73ac17d

Browse files
authored
Provide fetcher submission to shouldRevalidate if fetcher action redirects (#10208)
1 parent f3b593c commit 73ac17d

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed
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+
Provide fetcher submission to `shouldRevalidate` if the fetcher action redirects

packages/router/__tests__/router-test.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ function findRouteById(
187187
}
188188

189189
interface CustomMatchers<R = jest.Expect> {
190+
URL(url: string);
190191
trackedPromise(data?: any, error?: any, aborted?: boolean): R;
191192
deferredData(
192193
done: boolean,
@@ -204,6 +205,13 @@ declare global {
204205
}
205206

206207
expect.extend({
208+
// Custom matcher for asserting against URLs
209+
URL(received, url) {
210+
return {
211+
message: () => `expected URL ${received.toString()} to equal URL ${url}`,
212+
pass: received instanceof URL && received.toString() === url,
213+
};
214+
},
207215
// Custom matcher for asserting deferred promise results for static handler
208216
// - expect(val).deferredData(false) => Unresolved promise
209217
// - expect(val).deferredData(false) => Resolved promise
@@ -1825,12 +1833,12 @@ describe("a router", () => {
18251833
expect(rootLoader.mock.calls.length).toBe(1);
18261834
expect(shouldRevalidate.mock.calls[0][0]).toMatchObject({
18271835
currentParams: {},
1828-
currentUrl: new URL("http://localhost/child"),
1836+
currentUrl: expect.URL("http://localhost/child"),
18291837
nextParams: {
18301838
a: "aValue",
18311839
b: "bValue",
18321840
},
1833-
nextUrl: new URL("http://localhost/params/aValue/bValue"),
1841+
nextUrl: expect.URL("http://localhost/params/aValue/bValue"),
18341842
defaultShouldRevalidate: false,
18351843
actionResult: undefined,
18361844
});
@@ -1889,9 +1897,9 @@ describe("a router", () => {
18891897
let arg = shouldRevalidate.mock.calls[0][0];
18901898
expect(arg).toMatchObject({
18911899
currentParams: {},
1892-
currentUrl: new URL("http://localhost/child"),
1900+
currentUrl: expect.URL("http://localhost/child"),
18931901
nextParams: {},
1894-
nextUrl: new URL("http://localhost/child"),
1902+
nextUrl: expect.URL("http://localhost/child"),
18951903
defaultShouldRevalidate: true,
18961904
formMethod: "post",
18971905
formAction: "/child",
@@ -1942,9 +1950,9 @@ describe("a router", () => {
19421950
let arg = shouldRevalidate.mock.calls[0][0];
19431951
expect(arg).toMatchObject({
19441952
currentParams: {},
1945-
currentUrl: new URL("http://localhost/child"),
1953+
currentUrl: expect.URL("http://localhost/child"),
19461954
nextParams: {},
1947-
nextUrl: new URL("http://localhost/"),
1955+
nextUrl: expect.URL("http://localhost/"),
19481956
defaultShouldRevalidate: true,
19491957
formMethod: "post",
19501958
formAction: "/child",
@@ -2108,9 +2116,9 @@ describe("a router", () => {
21082116
expect(shouldRevalidate.mock.calls.length).toBe(1);
21092117
expect(shouldRevalidate.mock.calls[0][0]).toMatchObject({
21102118
currentParams: {},
2111-
currentUrl: new URL("http://localhost/"),
2119+
currentUrl: expect.URL("http://localhost/"),
21122120
nextParams: {},
2113-
nextUrl: new URL("http://localhost/child"),
2121+
nextUrl: expect.URL("http://localhost/child"),
21142122
defaultShouldRevalidate: false,
21152123
});
21162124
expect(router.state.fetchers.get(key)).toMatchObject({
@@ -2123,9 +2131,9 @@ describe("a router", () => {
21232131
expect(shouldRevalidate.mock.calls.length).toBe(2);
21242132
expect(shouldRevalidate.mock.calls[1][0]).toMatchObject({
21252133
currentParams: {},
2126-
currentUrl: new URL("http://localhost/child"),
2134+
currentUrl: expect.URL("http://localhost/child"),
21272135
nextParams: {},
2128-
nextUrl: new URL("http://localhost/"),
2136+
nextUrl: expect.URL("http://localhost/"),
21292137
defaultShouldRevalidate: false,
21302138
});
21312139
expect(router.state.fetchers.get(key)).toMatchObject({
@@ -2147,9 +2155,9 @@ describe("a router", () => {
21472155
expect(shouldRevalidate.mock.calls.length).toBe(3);
21482156
expect(shouldRevalidate.mock.calls[2][0]).toMatchObject({
21492157
currentParams: {},
2150-
currentUrl: new URL("http://localhost/"),
2158+
currentUrl: expect.URL("http://localhost/"),
21512159
nextParams: {},
2152-
nextUrl: new URL("http://localhost/child"),
2160+
nextUrl: expect.URL("http://localhost/child"),
21532161
formAction: "/child",
21542162
formData: createFormData({}),
21552163
formEncType: "application/x-www-form-urlencoded",
@@ -2269,6 +2277,10 @@ describe("a router", () => {
22692277
"currentParams": {},
22702278
"currentUrl": "http://localhost/",
22712279
"defaultShouldRevalidate": true,
2280+
"formAction": "/fetch",
2281+
"formData": FormData {},
2282+
"formEncType": "application/x-www-form-urlencoded",
2283+
"formMethod": "post",
22722284
"nextParams": {},
22732285
"nextUrl": "http://localhost/",
22742286
}

packages/router/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,7 @@ export function createRouter(init: RouterInit): Router {
16851685
updateState({ fetchers: new Map(state.fetchers) });
16861686

16871687
return startRedirectNavigation(state, actionResult, {
1688+
submission,
16881689
isFetchActionRedirect: true,
16891690
});
16901691
}

0 commit comments

Comments
 (0)