diff --git a/.changeset/remix-v2-prep.md b/.changeset/remix-v2-prep.md new file mode 100644 index 0000000000..ae2d111a54 --- /dev/null +++ b/.changeset/remix-v2-prep.md @@ -0,0 +1,5 @@ +--- +"@remix-run/router": patch +--- + +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 3333cdb849..3d16d2dd58 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ }, "filesize": { "packages/router/dist/router.umd.min.js": { - "none": "47.2 kB" + "none": "47.0 kB" }, "packages/react-router/dist/react-router.production.min.js": { "none": "13.8 kB" diff --git a/packages/router/__tests__/router-test.ts b/packages/router/__tests__/router-test.ts index 51fe38a0ff..615640944f 100644 --- a/packages/router/__tests__/router-test.ts +++ b/packages/router/__tests__/router-test.ts @@ -8750,7 +8750,6 @@ describe("a router", () => { formEncType: undefined, formData: undefined, data: undefined, - " _hasFetcherDoneAnything ": true, }); await dfd.resolve("DATA"); @@ -8760,7 +8759,6 @@ describe("a router", () => { formEncType: undefined, formData: undefined, data: "DATA", - " _hasFetcherDoneAnything ": true, }); expect(router._internalFetchControllers.size).toBe(0); @@ -9289,7 +9287,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 ca7163d13b..134e41d337 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" @@ -2135,12 +2125,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 && @@ -2154,23 +2153,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, }); @@ -4449,7 +4442,6 @@ function getLoadingFetcher( json: submission.json, text: submission.text, data, - " _hasFetcherDoneAnything ": true, }; return fetcher; } else { @@ -4462,7 +4454,6 @@ function getLoadingFetcher( json: undefined, text: undefined, data, - " _hasFetcherDoneAnything ": true, }; return fetcher; } @@ -4481,7 +4472,6 @@ function getSubmittingFetcher( json: submission.json, text: submission.text, data: existingFetcher ? existingFetcher.data : undefined, - " _hasFetcherDoneAnything ": true, }; return fetcher; } @@ -4496,7 +4486,6 @@ function getDoneFetcher(data: Fetcher["data"]): FetcherStates["Idle"] { json: undefined, text: undefined, data, - " _hasFetcherDoneAnything ": true, }; return fetcher; }