Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for Remix v2 #10715

Merged
merged 7 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/remix-v2-prep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": minor
---

Removed internal API only required for the Remix v1 back-compat layer and no longer needed in Remix v2. (`_isFetchActionRedirect`, `_hasFetcherDoneAnything`).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
},
"filesize": {
"packages/router/dist/router.umd.min.js": {
"none": "47.5 kB"
"none": "47.2 kB"
},
"packages/react-router/dist/react-router.production.min.js": {
"none": "13.9 kB"
Expand Down
3 changes: 0 additions & 3 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8871,7 +8871,6 @@ describe("a router", () => {
formEncType: undefined,
formData: undefined,
data: undefined,
" _hasFetcherDoneAnything ": true,
});

await dfd.resolve("DATA");
Expand All @@ -8881,7 +8880,6 @@ describe("a router", () => {
formEncType: undefined,
formData: undefined,
data: "DATA",
" _hasFetcherDoneAnything ": true,
});

expect(router._internalFetchControllers.size).toBe(0);
Expand Down Expand Up @@ -9410,7 +9408,6 @@ describe("a router", () => {
formAction: undefined,
formEncType: undefined,
formData: undefined,
" _hasFetcherDoneAnything ": true,
});
expect(t.router.state.historyAction).toBe("PUSH");
expect(t.router.state.location.pathname).toBe("/bar");
Expand Down
55 changes: 22 additions & 33 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ type FetcherStates<TData = any> = {
formData: undefined;
json: undefined;
data: TData | undefined;
" _hasFetcherDoneAnything "?: boolean;
};
Loading: {
state: "loading";
Expand All @@ -537,7 +536,6 @@ type FetcherStates<TData = any> = {
formData: Submission["formData"] | undefined;
json: Submission["json"] | undefined;
data: TData | undefined;
" _hasFetcherDoneAnything "?: boolean;
};
Submitting: {
state: "submitting";
Expand All @@ -548,7 +546,6 @@ type FetcherStates<TData = any> = {
formData: Submission["formData"];
json: Submission["json"];
data: TData | undefined;
" _hasFetcherDoneAnything "?: boolean;
};
};

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

return startRedirectNavigation(state, actionResult, {
submission,
isFetchActionRedirect: true,
fetcherSubmission: submission,
});
}
}
Expand Down Expand Up @@ -2086,27 +2082,21 @@ export function createRouter(init: RouterInit): Router {
redirect: RedirectResult,
{
submission,
fetcherSubmission,
replace,
isFetchActionRedirect,
}: {
submission?: Submission;
fetcherSubmission?: Submission;
replace?: boolean;
isFetchActionRedirect?: boolean;
} = {}
) {
if (redirect.revalidate) {
isRevalidationRequired = true;
}

let redirectLocation = createLocation(
state.location,
redirect.location,
// TODO: This can be removed once we get rid of useTransition in Remix v2
{
_isRedirect: true,
...(isFetchActionRedirect ? { _isFetchActionRedirect: true } : {}),
}
);
let redirectLocation = createLocation(state.location, redirect.location, {
_isRedirect: true,
});
invariant(
redirectLocation,
"Expected a location on the redirect navigation"
Expand Down Expand Up @@ -2146,12 +2136,21 @@ export function createRouter(init: RouterInit): Router {

// Use the incoming submission if provided, fallback on the active one in
// state.navigation
let activeSubmission =
submission || getSubmissionFromNavigation(state.navigation);
let { formMethod, formAction, formEncType } = state.navigation;
if (
!submission &&
!fetcherSubmission &&
formMethod &&
formAction &&
formEncType
) {
submission = getSubmissionFromNavigation(state.navigation);
}

// If this was a 307/308 submission we want to preserve the HTTP method and
// re-submit the GET/POST/PUT/PATCH/DELETE as a submission navigation to the
// redirected location
let activeSubmission = submission || fetcherSubmission;
if (
redirectPreserveMethodStatusCodes.has(redirect.status) &&
activeSubmission &&
Expand All @@ -2165,23 +2164,17 @@ export function createRouter(init: RouterInit): Router {
// Preserve this flag across redirects
preventScrollReset: pendingPreventScrollReset,
});
} else if (isFetchActionRedirect) {
// For a fetch action redirect, we kick off a new loading navigation
// without the fetcher submission, but we send it along for shouldRevalidate
await startNavigation(redirectHistoryAction, redirectLocation, {
overrideNavigation: getLoadingNavigation(redirectLocation),
fetcherSubmission: activeSubmission,
// Preserve this flag across redirects
preventScrollReset: pendingPreventScrollReset,
});
} else {
// If we have a submission, we will preserve it through the redirect navigation
// If we have a navigation submission, we will preserve it through the
// redirect navigation
let overrideNavigation = getLoadingNavigation(
redirectLocation,
activeSubmission
submission
);
await startNavigation(redirectHistoryAction, redirectLocation, {
overrideNavigation,
// Send fetcher submissions through for shouldRevalidate
fetcherSubmission,
// Preserve this flag across redirects
preventScrollReset: pendingPreventScrollReset,
});
Expand Down Expand Up @@ -4475,7 +4468,6 @@ function getLoadingFetcher(
json: submission.json,
text: submission.text,
data,
" _hasFetcherDoneAnything ": true,
};
return fetcher;
} else {
Expand All @@ -4488,7 +4480,6 @@ function getLoadingFetcher(
json: undefined,
text: undefined,
data,
" _hasFetcherDoneAnything ": true,
};
return fetcher;
}
Expand All @@ -4507,7 +4498,6 @@ function getSubmittingFetcher(
json: submission.json,
text: submission.text,
data: existingFetcher ? existingFetcher.data : undefined,
" _hasFetcherDoneAnything ": true,
};
return fetcher;
}
Expand All @@ -4522,7 +4512,6 @@ function getDoneFetcher(data: Fetcher["data"]): FetcherStates["Idle"] {
json: undefined,
text: undefined,
data,
" _hasFetcherDoneAnything ": true,
};
return fetcher;
}
Expand Down