Skip to content

Commit

Permalink
Remove flags (#11384)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Mar 29, 2024
1 parent fa82b2f commit 903b47f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 133 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-tips-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

[REMOVE] Remove staticHandler.query flags that we can implement in dataStrategy
1 change: 0 additions & 1 deletion .changeset/slow-flies-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions .changeset/static-query-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
50 changes: 0 additions & 50 deletions packages/router/__tests__/ssr-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
81 changes: 8 additions & 73 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ export interface StaticHandler {
query(
request: Request,
opts?: {
loadRouteIds?: string[];
requestContext?: unknown;
skipLoaders?: boolean;
skipLoaderErrorBubbling?: boolean;
unstable_dataStrategy?: DataStrategyFunction;
}
Expand Down Expand Up @@ -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<StaticHandlerContext | Response> {
Expand Down Expand Up @@ -3065,9 +3055,7 @@ export function createStaticHandler(
matches,
requestContext,
unstable_dataStrategy || null,
loadRouteIds || null,
skipLoaderErrorBubbling === true,
skipLoaders === true,
null
);
if (isResponse(result)) {
Expand Down Expand Up @@ -3145,11 +3133,10 @@ export function createStaticHandler(
matches,
requestContext,
null,
null,
false,
false,
match
);

if (isResponse(result)) {
return result;
}
Expand Down Expand Up @@ -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<Omit<StaticHandlerContext, "location" | "basename"> | Response> {
invariant(
Expand All @@ -3203,9 +3188,7 @@ export function createStaticHandler(
routeMatch || getTargetMatch(matches, location),
requestContext,
unstable_dataStrategy,
loadRouteIds,
skipLoaderErrorBubbling,
skipLoaders,
routeMatch != null
);
return result;
Expand All @@ -3216,7 +3199,6 @@ export function createStaticHandler(
matches,
requestContext,
unstable_dataStrategy,
loadRouteIds,
skipLoaderErrorBubbling,
routeMatch
);
Expand Down Expand Up @@ -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<Omit<StaticHandlerContext, "location" | "basename"> | Response> {
let result: DataResult;
Expand Down Expand Up @@ -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]
Expand All @@ -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,
};
}

Expand All @@ -3415,7 +3358,6 @@ export function createStaticHandler(
matches,
requestContext,
unstable_dataStrategy,
loadRouteIds,
skipLoaderErrorBubbling,
null
);
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 903b47f

Please sign in to comment.