Skip to content

Commit c265a42

Browse files
authoredAug 28, 2023
Prepare for Remix v2 (#10715)
1 parent 9852bb0 commit c265a42

File tree

4 files changed

+28
-37
lines changed

4 files changed

+28
-37
lines changed
 

‎.changeset/remix-v2-prep.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": minor
3+
---
4+
5+
Removed internal API only required for the Remix v1 back-compat layer and no longer needed in Remix v2. (`_isFetchActionRedirect`, `_hasFetcherDoneAnything`).

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
},
111111
"filesize": {
112112
"packages/router/dist/router.umd.min.js": {
113-
"none": "47.5 kB"
113+
"none": "47.2 kB"
114114
},
115115
"packages/react-router/dist/react-router.production.min.js": {
116116
"none": "13.9 kB"

‎packages/router/__tests__/router-test.ts

-3
Original file line numberDiff line numberDiff line change
@@ -8871,7 +8871,6 @@ describe("a router", () => {
88718871
formEncType: undefined,
88728872
formData: undefined,
88738873
data: undefined,
8874-
" _hasFetcherDoneAnything ": true,
88758874
});
88768875

88778876
await dfd.resolve("DATA");
@@ -8881,7 +8880,6 @@ describe("a router", () => {
88818880
formEncType: undefined,
88828881
formData: undefined,
88838882
data: "DATA",
8884-
" _hasFetcherDoneAnything ": true,
88858883
});
88868884

88878885
expect(router._internalFetchControllers.size).toBe(0);
@@ -9410,7 +9408,6 @@ describe("a router", () => {
94109408
formAction: undefined,
94119409
formEncType: undefined,
94129410
formData: undefined,
9413-
" _hasFetcherDoneAnything ": true,
94149411
});
94159412
expect(t.router.state.historyAction).toBe("PUSH");
94169413
expect(t.router.state.location.pathname).toBe("/bar");

‎packages/router/router.ts

+22-33
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,6 @@ type FetcherStates<TData = any> = {
526526
formData: undefined;
527527
json: undefined;
528528
data: TData | undefined;
529-
" _hasFetcherDoneAnything "?: boolean;
530529
};
531530
Loading: {
532531
state: "loading";
@@ -537,7 +536,6 @@ type FetcherStates<TData = any> = {
537536
formData: Submission["formData"] | undefined;
538537
json: Submission["json"] | undefined;
539538
data: TData | undefined;
540-
" _hasFetcherDoneAnything "?: boolean;
541539
};
542540
Submitting: {
543541
state: "submitting";
@@ -548,7 +546,6 @@ type FetcherStates<TData = any> = {
548546
formData: Submission["formData"];
549547
json: Submission["json"];
550548
data: TData | undefined;
551-
" _hasFetcherDoneAnything "?: boolean;
552549
};
553550
};
554551

@@ -1786,8 +1783,7 @@ export function createRouter(init: RouterInit): Router {
17861783
updateState({ fetchers: new Map(state.fetchers) });
17871784

17881785
return startRedirectNavigation(state, actionResult, {
1789-
submission,
1790-
isFetchActionRedirect: true,
1786+
fetcherSubmission: submission,
17911787
});
17921788
}
17931789
}
@@ -2086,27 +2082,21 @@ export function createRouter(init: RouterInit): Router {
20862082
redirect: RedirectResult,
20872083
{
20882084
submission,
2085+
fetcherSubmission,
20892086
replace,
2090-
isFetchActionRedirect,
20912087
}: {
20922088
submission?: Submission;
2089+
fetcherSubmission?: Submission;
20932090
replace?: boolean;
2094-
isFetchActionRedirect?: boolean;
20952091
} = {}
20962092
) {
20972093
if (redirect.revalidate) {
20982094
isRevalidationRequired = true;
20992095
}
21002096

2101-
let redirectLocation = createLocation(
2102-
state.location,
2103-
redirect.location,
2104-
// TODO: This can be removed once we get rid of useTransition in Remix v2
2105-
{
2106-
_isRedirect: true,
2107-
...(isFetchActionRedirect ? { _isFetchActionRedirect: true } : {}),
2108-
}
2109-
);
2097+
let redirectLocation = createLocation(state.location, redirect.location, {
2098+
_isRedirect: true,
2099+
});
21102100
invariant(
21112101
redirectLocation,
21122102
"Expected a location on the redirect navigation"
@@ -2146,12 +2136,21 @@ export function createRouter(init: RouterInit): Router {
21462136

21472137
// Use the incoming submission if provided, fallback on the active one in
21482138
// state.navigation
2149-
let activeSubmission =
2150-
submission || getSubmissionFromNavigation(state.navigation);
2139+
let { formMethod, formAction, formEncType } = state.navigation;
2140+
if (
2141+
!submission &&
2142+
!fetcherSubmission &&
2143+
formMethod &&
2144+
formAction &&
2145+
formEncType
2146+
) {
2147+
submission = getSubmissionFromNavigation(state.navigation);
2148+
}
21512149

21522150
// If this was a 307/308 submission we want to preserve the HTTP method and
21532151
// re-submit the GET/POST/PUT/PATCH/DELETE as a submission navigation to the
21542152
// redirected location
2153+
let activeSubmission = submission || fetcherSubmission;
21552154
if (
21562155
redirectPreserveMethodStatusCodes.has(redirect.status) &&
21572156
activeSubmission &&
@@ -2165,23 +2164,17 @@ export function createRouter(init: RouterInit): Router {
21652164
// Preserve this flag across redirects
21662165
preventScrollReset: pendingPreventScrollReset,
21672166
});
2168-
} else if (isFetchActionRedirect) {
2169-
// For a fetch action redirect, we kick off a new loading navigation
2170-
// without the fetcher submission, but we send it along for shouldRevalidate
2171-
await startNavigation(redirectHistoryAction, redirectLocation, {
2172-
overrideNavigation: getLoadingNavigation(redirectLocation),
2173-
fetcherSubmission: activeSubmission,
2174-
// Preserve this flag across redirects
2175-
preventScrollReset: pendingPreventScrollReset,
2176-
});
21772167
} else {
2178-
// If we have a submission, we will preserve it through the redirect navigation
2168+
// If we have a navigation submission, we will preserve it through the
2169+
// redirect navigation
21792170
let overrideNavigation = getLoadingNavigation(
21802171
redirectLocation,
2181-
activeSubmission
2172+
submission
21822173
);
21832174
await startNavigation(redirectHistoryAction, redirectLocation, {
21842175
overrideNavigation,
2176+
// Send fetcher submissions through for shouldRevalidate
2177+
fetcherSubmission,
21852178
// Preserve this flag across redirects
21862179
preventScrollReset: pendingPreventScrollReset,
21872180
});
@@ -4475,7 +4468,6 @@ function getLoadingFetcher(
44754468
json: submission.json,
44764469
text: submission.text,
44774470
data,
4478-
" _hasFetcherDoneAnything ": true,
44794471
};
44804472
return fetcher;
44814473
} else {
@@ -4488,7 +4480,6 @@ function getLoadingFetcher(
44884480
json: undefined,
44894481
text: undefined,
44904482
data,
4491-
" _hasFetcherDoneAnything ": true,
44924483
};
44934484
return fetcher;
44944485
}
@@ -4507,7 +4498,6 @@ function getSubmittingFetcher(
45074498
json: submission.json,
45084499
text: submission.text,
45094500
data: existingFetcher ? existingFetcher.data : undefined,
4510-
" _hasFetcherDoneAnything ": true,
45114501
};
45124502
return fetcher;
45134503
}
@@ -4522,7 +4512,6 @@ function getDoneFetcher(data: Fetcher["data"]): FetcherStates["Idle"] {
45224512
json: undefined,
45234513
text: undefined,
45244514
data,
4525-
" _hasFetcherDoneAnything ": true,
45264515
};
45274516
return fetcher;
45284517
}

0 commit comments

Comments
 (0)
Please sign in to comment.