diff --git a/.changeset/remix-v2-prep.md b/.changeset/remix-v2-prep.md new file mode 100644 index 0000000000..de557ff490 --- /dev/null +++ b/.changeset/remix-v2-prep.md @@ -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`). diff --git a/package.json b/package.json index 386a06881c..b82d2eecdb 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/packages/router/__tests__/router-test.ts b/packages/router/__tests__/router-test.ts index 11a121095f..8b05062659 100644 --- a/packages/router/__tests__/router-test.ts +++ b/packages/router/__tests__/router-test.ts @@ -8871,7 +8871,6 @@ describe("a router", () => { formEncType: undefined, formData: undefined, data: undefined, - " _hasFetcherDoneAnything ": true, }); await dfd.resolve("DATA"); @@ -8881,7 +8880,6 @@ describe("a router", () => { formEncType: undefined, formData: undefined, data: "DATA", - " _hasFetcherDoneAnything ": true, }); expect(router._internalFetchControllers.size).toBe(0); @@ -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"); diff --git a/packages/router/router.ts b/packages/router/router.ts index 86e5d94c4e..488ccc2b2b 100644 --- a/packages/router/router.ts +++ b/packages/router/router.ts @@ -526,7 +526,6 @@ type FetcherStates = { formData: undefined; json: undefined; data: TData | undefined; - " _hasFetcherDoneAnything "?: boolean; }; Loading: { state: "loading"; @@ -537,7 +536,6 @@ type FetcherStates = { formData: Submission["formData"] | undefined; json: Submission["json"] | undefined; data: TData | undefined; - " _hasFetcherDoneAnything "?: boolean; }; Submitting: { state: "submitting"; @@ -548,7 +546,6 @@ type FetcherStates = { formData: Submission["formData"]; json: Submission["json"]; data: TData | undefined; - " _hasFetcherDoneAnything "?: boolean; }; }; @@ -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, }); } } @@ -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" @@ -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 && @@ -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, }); @@ -4475,7 +4468,6 @@ function getLoadingFetcher( json: submission.json, text: submission.text, data, - " _hasFetcherDoneAnything ": true, }; return fetcher; } else { @@ -4488,7 +4480,6 @@ function getLoadingFetcher( json: undefined, text: undefined, data, - " _hasFetcherDoneAnything ": true, }; return fetcher; } @@ -4507,7 +4498,6 @@ function getSubmittingFetcher( json: submission.json, text: submission.text, data: existingFetcher ? existingFetcher.data : undefined, - " _hasFetcherDoneAnything ": true, }; return fetcher; } @@ -4522,7 +4512,6 @@ function getDoneFetcher(data: Fetcher["data"]): FetcherStates["Idle"] { json: undefined, text: undefined, data, - " _hasFetcherDoneAnything ": true, }; return fetcher; }