Skip to content

Commit 903b47f

Browse files
authored
Remove flags (#11384)
1 parent fa82b2f commit 903b47f

File tree

7 files changed

+16
-133
lines changed

7 files changed

+16
-133
lines changed

.changeset/funny-tips-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
[REMOVE] Remove staticHandler.query flags that we can implement in dataStrategy

.changeset/slow-flies-help.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
---
44

55
- 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.
6-
- Added a new `skipLoaders` flag to `staticHandler.query` for calling only the action in Remix Single Fetch

.changeset/static-query-flags.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22
"@remix-run/router": minor
33
---
44

5-
Added 2 new options to the `staticHandler.query` method for use in Remix's Single Fetch implementation:
6-
7-
- `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)
8-
- `skipLoaderErrorBubbling`: Disable error bubbling on loader executions for single-fetch scenarios where the client-side router will handle the bubbling
5+
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

CHANGELOG.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ With this flag enabled, `action`'s that return/throw a `4xx`/`5xx` response stat
202202

203203
- 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)))
204204
- `@remix-run/router` - Add a new `future.unstable_skipActionRevalidation` future flag ([#11098](https://github.com/remix-run/react-router/pull/11098))
205-
- `@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)))
206-
- `loadRouteIds`: Optional array of route IDs to load a subset of the matched routes
207-
- `skipLoaderErrorBubbling`: Disable error bubbling by the static handler
208-
- `skipLoaders`: Only call the action on POST requests, don't call all of the loaders afterwards
205+
- `@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)))
209206

210207
**Full Changelog**: [`v6.22.3...v6.23.0`](https://github.com/remix-run/react-router/compare/[email protected]@6.23.0)
211208

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"none": "14.8 kB"
112112
},
113113
"packages/react-router/dist/umd/react-router.production.min.js": {
114-
"none": "17.2 kB"
114+
"none": "17.21 kB"
115115
},
116116
"packages/react-router-dom/dist/react-router-dom.production.min.js": {
117117
"none": "17.1 kB"

packages/router/__tests__/ssr-test.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,56 +1090,6 @@ describe("ssr", () => {
10901090
expect(arg(childStub).context.sessionId).toBe("12345");
10911091
});
10921092

1093-
it("should support a loadRouteIds parameter for granular loads", async () => {
1094-
let rootStub = jest.fn(() => "ROOT");
1095-
let childStub = jest.fn(() => "CHILD");
1096-
let actionStub = jest.fn(() => "CHILD ACTION");
1097-
let { query } = createStaticHandler([
1098-
{
1099-
id: "root",
1100-
path: "/",
1101-
loader: rootStub,
1102-
children: [
1103-
{
1104-
id: "child",
1105-
path: "child",
1106-
action: actionStub,
1107-
loader: childStub,
1108-
},
1109-
],
1110-
},
1111-
]);
1112-
1113-
let ctx = await query(createRequest("/child"), {
1114-
loadRouteIds: ["child"],
1115-
});
1116-
expect(rootStub).not.toHaveBeenCalled();
1117-
expect(childStub).toHaveBeenCalled();
1118-
expect(ctx).toMatchObject({
1119-
loaderData: {
1120-
child: "CHILD",
1121-
},
1122-
});
1123-
1124-
actionStub.mockClear();
1125-
rootStub.mockClear();
1126-
childStub.mockClear();
1127-
1128-
ctx = await query(createSubmitRequest("/child"), {
1129-
loadRouteIds: ["child"],
1130-
});
1131-
expect(rootStub).not.toHaveBeenCalled();
1132-
expect(childStub).toHaveBeenCalled();
1133-
expect(ctx).toMatchObject({
1134-
actionData: {
1135-
child: "CHILD ACTION",
1136-
},
1137-
loaderData: {
1138-
child: "CHILD",
1139-
},
1140-
});
1141-
});
1142-
11431093
describe("deferred", () => {
11441094
let { query } = createStaticHandler(SSR_ROUTES);
11451095

packages/router/router.ts

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,7 @@ export interface StaticHandler {
405405
query(
406406
request: Request,
407407
opts?: {
408-
loadRouteIds?: string[];
409408
requestContext?: unknown;
410-
skipLoaders?: boolean;
411409
skipLoaderErrorBubbling?: boolean;
412410
unstable_dataStrategy?: DataStrategyFunction;
413411
}
@@ -2988,30 +2986,22 @@ export function createStaticHandler(
29882986
* propagate that out and return the raw Response so the HTTP server can
29892987
* return it directly.
29902988
*
2991-
* - `opts.loadRouteIds` is an optional array of routeIds to run only a subset of
2992-
* loaders during a query() call
29932989
* - `opts.requestContext` is an optional server context that will be passed
29942990
* to actions/loaders in the `context` parameter
29952991
* - `opts.skipLoaderErrorBubbling` is an optional parameter that will prevent
29962992
* the bubbling of errors which allows single-fetch-type implementations
29972993
* where the client will handle the bubbling and we may need to return data
29982994
* for the handling route
2999-
* - `opts.skipLoaders` is an optional parameter that will prevent loaders
3000-
* from running after an action
30012995
*/
30022996
async function query(
30032997
request: Request,
30042998
{
3005-
loadRouteIds,
30062999
requestContext,
30073000
skipLoaderErrorBubbling,
3008-
skipLoaders,
30093001
unstable_dataStrategy,
30103002
}: {
3011-
loadRouteIds?: string[];
30123003
requestContext?: unknown;
30133004
skipLoaderErrorBubbling?: boolean;
3014-
skipLoaders?: boolean;
30153005
unstable_dataStrategy?: DataStrategyFunction;
30163006
} = {}
30173007
): Promise<StaticHandlerContext | Response> {
@@ -3065,9 +3055,7 @@ export function createStaticHandler(
30653055
matches,
30663056
requestContext,
30673057
unstable_dataStrategy || null,
3068-
loadRouteIds || null,
30693058
skipLoaderErrorBubbling === true,
3070-
skipLoaders === true,
30713059
null
30723060
);
30733061
if (isResponse(result)) {
@@ -3145,11 +3133,10 @@ export function createStaticHandler(
31453133
matches,
31463134
requestContext,
31473135
null,
3148-
null,
3149-
false,
31503136
false,
31513137
match
31523138
);
3139+
31533140
if (isResponse(result)) {
31543141
return result;
31553142
}
@@ -3185,9 +3172,7 @@ export function createStaticHandler(
31853172
matches: AgnosticDataRouteMatch[],
31863173
requestContext: unknown,
31873174
unstable_dataStrategy: DataStrategyFunction | null,
3188-
loadRouteIds: string[] | null,
31893175
skipLoaderErrorBubbling: boolean,
3190-
skipLoaders: boolean,
31913176
routeMatch: AgnosticDataRouteMatch | null
31923177
): Promise<Omit<StaticHandlerContext, "location" | "basename"> | Response> {
31933178
invariant(
@@ -3203,9 +3188,7 @@ export function createStaticHandler(
32033188
routeMatch || getTargetMatch(matches, location),
32043189
requestContext,
32053190
unstable_dataStrategy,
3206-
loadRouteIds,
32073191
skipLoaderErrorBubbling,
3208-
skipLoaders,
32093192
routeMatch != null
32103193
);
32113194
return result;
@@ -3216,7 +3199,6 @@ export function createStaticHandler(
32163199
matches,
32173200
requestContext,
32183201
unstable_dataStrategy,
3219-
loadRouteIds,
32203202
skipLoaderErrorBubbling,
32213203
routeMatch
32223204
);
@@ -3252,9 +3234,7 @@ export function createStaticHandler(
32523234
actionMatch: AgnosticDataRouteMatch,
32533235
requestContext: unknown,
32543236
unstable_dataStrategy: DataStrategyFunction | null,
3255-
loadRouteIds: string[] | null,
32563237
skipLoaderErrorBubbling: boolean,
3257-
skipLoaders: boolean,
32583238
isRouteRequest: boolean
32593239
): Promise<Omit<StaticHandlerContext, "location" | "basename"> | Response> {
32603240
let result: DataResult;
@@ -3347,36 +3327,12 @@ export function createStaticHandler(
33473327
let boundaryMatch = skipLoaderErrorBubbling
33483328
? actionMatch
33493329
: findNearestBoundary(matches, actionMatch.route.id);
3350-
let statusCode = isRouteErrorResponse(result.error)
3351-
? result.error.status
3352-
: result.statusCode != null
3353-
? result.statusCode
3354-
: 500;
3355-
let actionHeaders = {
3356-
...(result.headers ? { [actionMatch.route.id]: result.headers } : {}),
3357-
};
3358-
3359-
if (skipLoaders) {
3360-
return {
3361-
matches,
3362-
loaderData: {},
3363-
actionData: {},
3364-
errors: {
3365-
[boundaryMatch.route.id]: result.error,
3366-
},
3367-
statusCode,
3368-
loaderHeaders: {},
3369-
actionHeaders,
3370-
activeDeferreds: null,
3371-
};
3372-
}
33733330

33743331
let context = await loadRouteData(
33753332
loaderRequest,
33763333
matches,
33773334
requestContext,
33783335
unstable_dataStrategy,
3379-
loadRouteIds,
33803336
skipLoaderErrorBubbling,
33813337
null,
33823338
[boundaryMatch.route.id, result]
@@ -3385,28 +3341,15 @@ export function createStaticHandler(
33853341
// action status codes take precedence over loader status codes
33863342
return {
33873343
...context,
3388-
statusCode,
3344+
statusCode: isRouteErrorResponse(result.error)
3345+
? result.error.status
3346+
: result.statusCode != null
3347+
? result.statusCode
3348+
: 500,
33893349
actionData: null,
3390-
actionHeaders,
3391-
};
3392-
}
3393-
3394-
let actionHeaders = result.headers
3395-
? { [actionMatch.route.id]: result.headers }
3396-
: {};
3397-
3398-
if (skipLoaders) {
3399-
return {
3400-
matches,
3401-
loaderData: {},
3402-
actionData: {
3403-
[actionMatch.route.id]: result.data,
3350+
actionHeaders: {
3351+
...(result.headers ? { [actionMatch.route.id]: result.headers } : {}),
34043352
},
3405-
errors: null,
3406-
statusCode: result.statusCode || 200,
3407-
loaderHeaders: {},
3408-
actionHeaders,
3409-
activeDeferreds: null,
34103353
};
34113354
}
34123355

@@ -3415,7 +3358,6 @@ export function createStaticHandler(
34153358
matches,
34163359
requestContext,
34173360
unstable_dataStrategy,
3418-
loadRouteIds,
34193361
skipLoaderErrorBubbling,
34203362
null
34213363
);
@@ -3438,7 +3380,6 @@ export function createStaticHandler(
34383380
matches: AgnosticDataRouteMatch[],
34393381
requestContext: unknown,
34403382
unstable_dataStrategy: DataStrategyFunction | null,
3441-
loadRouteIds: string[] | null,
34423383
skipLoaderErrorBubbling: boolean,
34433384
routeMatch: AgnosticDataRouteMatch | null,
34443385
pendingActionResult?: PendingActionResult
@@ -3473,12 +3414,6 @@ export function createStaticHandler(
34733414
(m) => m.route.loader || m.route.lazy
34743415
);
34753416

3476-
if (loadRouteIds) {
3477-
matchesToLoad = matchesToLoad.filter((m) =>
3478-
loadRouteIds.includes(m.route.id)
3479-
);
3480-
}
3481-
34823417
// Short circuit if we have no loaders to run (query())
34833418
if (matchesToLoad.length === 0) {
34843419
return {

0 commit comments

Comments
 (0)