From 903b47fadd82cce5d4abad8f2460288c3c3da73f Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Fri, 29 Mar 2024 14:44:44 -0400 Subject: [PATCH] Remove flags (#11384) --- .changeset/funny-tips-beg.md | 5 ++ .changeset/slow-flies-help.md | 1 - .changeset/static-query-flags.md | 5 +- CHANGELOG.md | 5 +- package.json | 2 +- packages/router/__tests__/ssr-test.ts | 50 ----------------- packages/router/router.ts | 81 +++------------------------ 7 files changed, 16 insertions(+), 133 deletions(-) create mode 100644 .changeset/funny-tips-beg.md diff --git a/.changeset/funny-tips-beg.md b/.changeset/funny-tips-beg.md new file mode 100644 index 0000000000..f3ef8818e7 --- /dev/null +++ b/.changeset/funny-tips-beg.md @@ -0,0 +1,5 @@ +--- +"@remix-run/router": patch +--- + +[REMOVE] Remove staticHandler.query flags that we can implement in dataStrategy diff --git a/.changeset/slow-flies-help.md b/.changeset/slow-flies-help.md index 94d7064ecb..26479b827d 100644 --- a/.changeset/slow-flies-help.md +++ b/.changeset/slow-flies-help.md @@ -3,4 +3,3 @@ --- - Move `unstable_dataStrategy` from `createStaticHandler` to `staticHandler.query` so it can be request-specific for use with the `ResponseStub` approach in Remix. It's not really applicable to `queryRoute` for now since that's a singular handler call anyway so any pre-processing/post/processing could be done there manually. -- Added a new `skipLoaders` flag to `staticHandler.query` for calling only the action in Remix Single Fetch diff --git a/.changeset/static-query-flags.md b/.changeset/static-query-flags.md index 5bca02eca7..bbdfebc292 100644 --- a/.changeset/static-query-flags.md +++ b/.changeset/static-query-flags.md @@ -2,7 +2,4 @@ "@remix-run/router": minor --- -Added 2 new options to the `staticHandler.query` method for use in Remix's Single Fetch implementation: - -- `loadRouteIds`: An optional array of route IDs to load if you wish to load a subset of the matched routes (useful for fine-grained revalidation) -- `skipLoaderErrorBubbling`: Disable error bubbling on loader executions for single-fetch scenarios where the client-side router will handle the bubbling +Added a `skipLoaderErrorBubbling` flag to `staticHandler.query` to disable error bubbling on loader executions for single-fetch scenarios where the client-side router will handle the bubbling diff --git a/CHANGELOG.md b/CHANGELOG.md index f36c3c8ec0..0d3c549461 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -202,10 +202,7 @@ With this flag enabled, `action`'s that return/throw a `4xx`/`5xx` response stat - Add a new `unstable_dataStrategy` configuration option ([#11098](https://github.com/remix-run/react-router/pull/11098), ([#11377](https://github.com/remix-run/react-router/pull/11377))) - `@remix-run/router` - Add a new `future.unstable_skipActionRevalidation` future flag ([#11098](https://github.com/remix-run/react-router/pull/11098)) -- `@remix-run/router` - SSR: Added 3 new options to the `staticHandler.query` method for use in Remix's Single Fetch implementation: ([#11098](https://github.com/remix-run/react-router/pull/11098), ([#11377](https://github.com/remix-run/react-router/pull/11377))) - - `loadRouteIds`: Optional array of route IDs to load a subset of the matched routes - - `skipLoaderErrorBubbling`: Disable error bubbling by the static handler - - `skipLoaders`: Only call the action on POST requests, don't call all of the loaders afterwards +- `@remix-run/router` - SSR: Added a new `skipLoaderErrorBubbling` options to the `staticHandler.query` method to disable error bubbling by the static handler for use in Remix's Single Fetch implementation ([#11098](https://github.com/remix-run/react-router/pull/11098), ([#11377](https://github.com/remix-run/react-router/pull/11377))) **Full Changelog**: [`v6.22.3...v6.23.0`](https://github.com/remix-run/react-router/compare/react-router@6.22.3...react-router@6.23.0) diff --git a/package.json b/package.json index 605d1b9aca..af7348a3d1 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "none": "14.8 kB" }, "packages/react-router/dist/umd/react-router.production.min.js": { - "none": "17.2 kB" + "none": "17.21 kB" }, "packages/react-router-dom/dist/react-router-dom.production.min.js": { "none": "17.1 kB" diff --git a/packages/router/__tests__/ssr-test.ts b/packages/router/__tests__/ssr-test.ts index 19061e15e9..7795c08f70 100644 --- a/packages/router/__tests__/ssr-test.ts +++ b/packages/router/__tests__/ssr-test.ts @@ -1090,56 +1090,6 @@ describe("ssr", () => { expect(arg(childStub).context.sessionId).toBe("12345"); }); - it("should support a loadRouteIds parameter for granular loads", async () => { - let rootStub = jest.fn(() => "ROOT"); - let childStub = jest.fn(() => "CHILD"); - let actionStub = jest.fn(() => "CHILD ACTION"); - let { query } = createStaticHandler([ - { - id: "root", - path: "/", - loader: rootStub, - children: [ - { - id: "child", - path: "child", - action: actionStub, - loader: childStub, - }, - ], - }, - ]); - - let ctx = await query(createRequest("/child"), { - loadRouteIds: ["child"], - }); - expect(rootStub).not.toHaveBeenCalled(); - expect(childStub).toHaveBeenCalled(); - expect(ctx).toMatchObject({ - loaderData: { - child: "CHILD", - }, - }); - - actionStub.mockClear(); - rootStub.mockClear(); - childStub.mockClear(); - - ctx = await query(createSubmitRequest("/child"), { - loadRouteIds: ["child"], - }); - expect(rootStub).not.toHaveBeenCalled(); - expect(childStub).toHaveBeenCalled(); - expect(ctx).toMatchObject({ - actionData: { - child: "CHILD ACTION", - }, - loaderData: { - child: "CHILD", - }, - }); - }); - describe("deferred", () => { let { query } = createStaticHandler(SSR_ROUTES); diff --git a/packages/router/router.ts b/packages/router/router.ts index e99b844e66..7a7d2c0a61 100644 --- a/packages/router/router.ts +++ b/packages/router/router.ts @@ -405,9 +405,7 @@ export interface StaticHandler { query( request: Request, opts?: { - loadRouteIds?: string[]; requestContext?: unknown; - skipLoaders?: boolean; skipLoaderErrorBubbling?: boolean; unstable_dataStrategy?: DataStrategyFunction; } @@ -2988,30 +2986,22 @@ export function createStaticHandler( * propagate that out and return the raw Response so the HTTP server can * return it directly. * - * - `opts.loadRouteIds` is an optional array of routeIds to run only a subset of - * loaders during a query() call * - `opts.requestContext` is an optional server context that will be passed * to actions/loaders in the `context` parameter * - `opts.skipLoaderErrorBubbling` is an optional parameter that will prevent * the bubbling of errors which allows single-fetch-type implementations * where the client will handle the bubbling and we may need to return data * for the handling route - * - `opts.skipLoaders` is an optional parameter that will prevent loaders - * from running after an action */ async function query( request: Request, { - loadRouteIds, requestContext, skipLoaderErrorBubbling, - skipLoaders, unstable_dataStrategy, }: { - loadRouteIds?: string[]; requestContext?: unknown; skipLoaderErrorBubbling?: boolean; - skipLoaders?: boolean; unstable_dataStrategy?: DataStrategyFunction; } = {} ): Promise { @@ -3065,9 +3055,7 @@ export function createStaticHandler( matches, requestContext, unstable_dataStrategy || null, - loadRouteIds || null, skipLoaderErrorBubbling === true, - skipLoaders === true, null ); if (isResponse(result)) { @@ -3145,11 +3133,10 @@ export function createStaticHandler( matches, requestContext, null, - null, - false, false, match ); + if (isResponse(result)) { return result; } @@ -3185,9 +3172,7 @@ export function createStaticHandler( matches: AgnosticDataRouteMatch[], requestContext: unknown, unstable_dataStrategy: DataStrategyFunction | null, - loadRouteIds: string[] | null, skipLoaderErrorBubbling: boolean, - skipLoaders: boolean, routeMatch: AgnosticDataRouteMatch | null ): Promise | Response> { invariant( @@ -3203,9 +3188,7 @@ export function createStaticHandler( routeMatch || getTargetMatch(matches, location), requestContext, unstable_dataStrategy, - loadRouteIds, skipLoaderErrorBubbling, - skipLoaders, routeMatch != null ); return result; @@ -3216,7 +3199,6 @@ export function createStaticHandler( matches, requestContext, unstable_dataStrategy, - loadRouteIds, skipLoaderErrorBubbling, routeMatch ); @@ -3252,9 +3234,7 @@ export function createStaticHandler( actionMatch: AgnosticDataRouteMatch, requestContext: unknown, unstable_dataStrategy: DataStrategyFunction | null, - loadRouteIds: string[] | null, skipLoaderErrorBubbling: boolean, - skipLoaders: boolean, isRouteRequest: boolean ): Promise | Response> { let result: DataResult; @@ -3347,36 +3327,12 @@ export function createStaticHandler( let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id); - let statusCode = isRouteErrorResponse(result.error) - ? result.error.status - : result.statusCode != null - ? result.statusCode - : 500; - let actionHeaders = { - ...(result.headers ? { [actionMatch.route.id]: result.headers } : {}), - }; - - if (skipLoaders) { - return { - matches, - loaderData: {}, - actionData: {}, - errors: { - [boundaryMatch.route.id]: result.error, - }, - statusCode, - loaderHeaders: {}, - actionHeaders, - activeDeferreds: null, - }; - } let context = await loadRouteData( loaderRequest, matches, requestContext, unstable_dataStrategy, - loadRouteIds, skipLoaderErrorBubbling, null, [boundaryMatch.route.id, result] @@ -3385,28 +3341,15 @@ export function createStaticHandler( // action status codes take precedence over loader status codes return { ...context, - statusCode, + statusCode: isRouteErrorResponse(result.error) + ? result.error.status + : result.statusCode != null + ? result.statusCode + : 500, actionData: null, - actionHeaders, - }; - } - - let actionHeaders = result.headers - ? { [actionMatch.route.id]: result.headers } - : {}; - - if (skipLoaders) { - return { - matches, - loaderData: {}, - actionData: { - [actionMatch.route.id]: result.data, + actionHeaders: { + ...(result.headers ? { [actionMatch.route.id]: result.headers } : {}), }, - errors: null, - statusCode: result.statusCode || 200, - loaderHeaders: {}, - actionHeaders, - activeDeferreds: null, }; } @@ -3415,7 +3358,6 @@ export function createStaticHandler( matches, requestContext, unstable_dataStrategy, - loadRouteIds, skipLoaderErrorBubbling, null ); @@ -3438,7 +3380,6 @@ export function createStaticHandler( matches: AgnosticDataRouteMatch[], requestContext: unknown, unstable_dataStrategy: DataStrategyFunction | null, - loadRouteIds: string[] | null, skipLoaderErrorBubbling: boolean, routeMatch: AgnosticDataRouteMatch | null, pendingActionResult?: PendingActionResult @@ -3473,12 +3414,6 @@ export function createStaticHandler( (m) => m.route.loader || m.route.lazy ); - if (loadRouteIds) { - matchesToLoad = matchesToLoad.filter((m) => - loadRouteIds.includes(m.route.id) - ); - } - // Short circuit if we have no loaders to run (query()) if (matchesToLoad.length === 0) { return {