Skip to content

Commit 6111684

Browse files
committed
Temp
1 parent 12afb2e commit 6111684

File tree

1 file changed

+61
-9
lines changed

1 file changed

+61
-9
lines changed

packages/router/router.ts

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ export interface StaticHandler {
407407
opts?: {
408408
loadRouteIds?: string[];
409409
requestContext?: unknown;
410+
skipLoaders?: boolean;
410411
skipLoaderErrorBubbling?: boolean;
411412
}
412413
): Promise<StaticHandlerContext | Response>;
@@ -2988,25 +2989,29 @@ export function createStaticHandler(
29882989
* propagate that out and return the raw Response so the HTTP server can
29892990
* return it directly.
29902991
*
2991-
* - `opts.loadRouteIds` is an optional array of routeIds if you wish to only
2992-
* run a subset of route loaders on a GET request
2992+
* - `opts.loadRouteIds` is an optional array of routeIds to run only a subset of
2993+
* loaders during a query() call
29932994
* - `opts.requestContext` is an optional server context that will be passed
29942995
* to actions/loaders in the `context` parameter
29952996
* - `opts.skipLoaderErrorBubbling` is an optional parameter that will prevent
2996-
* the bubbling of loader errors which allows single-fetch-type implementations
2997+
* the bubbling of errors which allows single-fetch-type implementations
29972998
* where the client will handle the bubbling and we may need to return data
29982999
* for the handling route
3000+
* - `opts.skipLoaders` is an optional parameter that will prevent loaders
3001+
* from running after an action
29993002
*/
30003003
async function query(
30013004
request: Request,
30023005
{
30033006
loadRouteIds,
30043007
requestContext,
30053008
skipLoaderErrorBubbling,
3009+
skipLoaders,
30063010
}: {
30073011
loadRouteIds?: string[];
30083012
requestContext?: unknown;
30093013
skipLoaderErrorBubbling?: boolean;
3014+
skipLoaders?: boolean;
30103015
} = {}
30113016
): Promise<StaticHandlerContext | Response> {
30123017
let url = new URL(request.url);
@@ -3060,6 +3065,7 @@ export function createStaticHandler(
30603065
requestContext,
30613066
loadRouteIds || null,
30623067
skipLoaderErrorBubbling === true,
3068+
skipLoaders === true,
30633069
null
30643070
);
30653071
if (isResponse(result)) {
@@ -3138,6 +3144,7 @@ export function createStaticHandler(
31383144
requestContext,
31393145
null,
31403146
false,
3147+
false,
31413148
match
31423149
);
31433150
if (isResponse(result)) {
@@ -3176,6 +3183,7 @@ export function createStaticHandler(
31763183
requestContext: unknown,
31773184
loadRouteIds: string[] | null,
31783185
skipLoaderErrorBubbling: boolean,
3186+
skipLoaders: boolean,
31793187
routeMatch: AgnosticDataRouteMatch | null
31803188
): Promise<Omit<StaticHandlerContext, "location" | "basename"> | Response> {
31813189
invariant(
@@ -3192,6 +3200,7 @@ export function createStaticHandler(
31923200
requestContext,
31933201
loadRouteIds,
31943202
skipLoaderErrorBubbling,
3203+
skipLoaders,
31953204
routeMatch != null
31963205
);
31973206
return result;
@@ -3238,6 +3247,7 @@ export function createStaticHandler(
32383247
requestContext: unknown,
32393248
loadRouteIds: string[] | null,
32403249
skipLoaderErrorBubbling: boolean,
3250+
skipLoaders: boolean,
32413251
isRouteRequest: boolean
32423252
): Promise<Omit<StaticHandlerContext, "location" | "basename"> | Response> {
32433253
let result: DataResult;
@@ -3326,7 +3336,33 @@ export function createStaticHandler(
33263336
if (isErrorResult(result)) {
33273337
// Store off the pending error - we use it to determine which loaders
33283338
// to call and will commit it when we complete the navigation
3329-
let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id);
3339+
let boundaryMatch = skipLoaderErrorBubbling
3340+
? actionMatch
3341+
: findNearestBoundary(matches, actionMatch.route.id);
3342+
let statusCode = isRouteErrorResponse(result.error)
3343+
? result.error.status
3344+
: result.statusCode != null
3345+
? result.statusCode
3346+
: 500;
3347+
let actionHeaders = {
3348+
...(result.headers ? { [actionMatch.route.id]: result.headers } : {}),
3349+
};
3350+
3351+
if (skipLoaders) {
3352+
return {
3353+
matches,
3354+
loaderData: {},
3355+
actionData: {},
3356+
errors: {
3357+
[boundaryMatch.route.id]: result.error,
3358+
},
3359+
statusCode,
3360+
loaderHeaders: {},
3361+
actionHeaders,
3362+
activeDeferreds: null,
3363+
};
3364+
}
3365+
33303366
let context = await loadRouteData(
33313367
loaderRequest,
33323368
matches,
@@ -3340,13 +3376,28 @@ export function createStaticHandler(
33403376
// action status codes take precedence over loader status codes
33413377
return {
33423378
...context,
3343-
statusCode: isRouteErrorResponse(result.error)
3344-
? result.error.status
3345-
: 500,
3379+
statusCode,
33463380
actionData: null,
3347-
actionHeaders: {
3348-
...(result.headers ? { [actionMatch.route.id]: result.headers } : {}),
3381+
actionHeaders,
3382+
};
3383+
}
3384+
3385+
let actionHeaders = result.headers
3386+
? { [actionMatch.route.id]: result.headers }
3387+
: {};
3388+
3389+
if (skipLoaders) {
3390+
return {
3391+
matches,
3392+
loaderData: {},
3393+
actionData: {
3394+
[actionMatch.route.id]: result.data,
33493395
},
3396+
errors: null,
3397+
statusCode: result.statusCode || 200,
3398+
loaderHeaders: {},
3399+
actionHeaders,
3400+
activeDeferreds: null,
33503401
};
33513402
}
33523403

@@ -4188,6 +4239,7 @@ async function callDataStrategyImpl(
41884239
}),
41894240
request,
41904241
params: matches[0].params,
4242+
context: requestContext,
41914243
});
41924244

41934245
// Throw if any loadRoute implementations not called since they are what

0 commit comments

Comments
 (0)