react-router 7.7.1 → 7.8.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -5
- package/dist/development/browser-z32v5KVN.d.mts +46 -0
- package/dist/{production/chunk-K3SBCRK4.mjs → development/chunk-HSC5IU24.mjs} +177 -134
- package/dist/development/{chunk-K7YFBME3.js → chunk-IW6UADHO.js} +250 -187
- package/dist/development/{chunk-C37GKA54.mjs → chunk-SC4OUYO4.mjs} +232 -169
- package/dist/development/{chunk-R73PQUJU.js → chunk-Z4NNCWGU.js} +130 -130
- package/dist/development/{components-CjQijYga.d.mts → components-uUh0svuC.d.mts} +33 -21
- package/dist/{production/route-data-CqEmXQub.d.mts → development/context-DZWGFcKX.d.mts} +312 -524
- package/dist/development/dom-export.d.mts +16 -12
- package/dist/development/dom-export.d.ts +13 -8
- package/dist/development/dom-export.js +3 -3
- package/dist/development/dom-export.mjs +3 -3
- package/dist/{production/index-react-server-client-KLg-U4nr.d.mts → development/index-react-server-client-BUK-oRcG.d.mts} +327 -200
- package/dist/development/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-DSU6bZil.d.ts} +357 -219
- package/dist/development/index-react-server-client.d.mts +4 -3
- package/dist/development/index-react-server-client.d.ts +2 -2
- package/dist/development/index-react-server-client.js +4 -4
- package/dist/development/index-react-server-client.mjs +2 -2
- package/dist/development/index-react-server.d.mts +291 -70
- package/dist/development/index-react-server.d.ts +291 -70
- package/dist/development/index-react-server.js +174 -180
- package/dist/development/index-react-server.mjs +174 -180
- package/dist/development/index.d.mts +294 -86
- package/dist/development/index.d.ts +136 -105
- package/dist/development/index.js +258 -215
- package/dist/development/index.mjs +3 -3
- package/dist/development/lib/types/internal.d.mts +13 -2
- package/dist/development/lib/types/internal.d.ts +12 -2
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/development/route-data-UTmTa8an.d.mts +473 -0
- package/dist/{production/routeModules-BR2FO0ix.d.ts → development/routeModules-D5bppTB2.d.ts} +325 -67
- package/dist/production/browser-z32v5KVN.d.mts +46 -0
- package/dist/production/{chunk-4DGLNKXF.js → chunk-BCLZG6QW.js} +130 -130
- package/dist/{development/chunk-KIUJAIYX.mjs → production/chunk-KQ5567DT.mjs} +177 -134
- package/dist/production/{chunk-IZ57JD2V.mjs → chunk-X2NPJMV2.mjs} +232 -169
- package/dist/production/{chunk-7OQROU2D.js → chunk-YC2ENCM3.js} +250 -187
- package/dist/production/{components-CjQijYga.d.mts → components-uUh0svuC.d.mts} +33 -21
- package/dist/{development/route-data-CqEmXQub.d.mts → production/context-DZWGFcKX.d.mts} +312 -524
- package/dist/production/dom-export.d.mts +16 -12
- package/dist/production/dom-export.d.ts +13 -8
- package/dist/production/dom-export.js +3 -3
- package/dist/production/dom-export.mjs +3 -3
- package/dist/{development/index-react-server-client-KLg-U4nr.d.mts → production/index-react-server-client-BUK-oRcG.d.mts} +327 -200
- package/dist/production/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-DSU6bZil.d.ts} +357 -219
- package/dist/production/index-react-server-client.d.mts +4 -3
- package/dist/production/index-react-server-client.d.ts +2 -2
- package/dist/production/index-react-server-client.js +4 -4
- package/dist/production/index-react-server-client.mjs +2 -2
- package/dist/production/index-react-server.d.mts +291 -70
- package/dist/production/index-react-server.d.ts +291 -70
- package/dist/production/index-react-server.js +174 -180
- package/dist/production/index-react-server.mjs +174 -180
- package/dist/production/index.d.mts +294 -86
- package/dist/production/index.d.ts +136 -105
- package/dist/production/index.js +258 -215
- package/dist/production/index.mjs +3 -3
- package/dist/production/lib/types/internal.d.mts +13 -2
- package/dist/production/lib/types/internal.d.ts +12 -2
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/production/route-data-UTmTa8an.d.mts +473 -0
- package/dist/{development/routeModules-BR2FO0ix.d.ts → production/routeModules-D5bppTB2.d.ts} +325 -67
- package/package.json +1 -1
- package/dist/development/browser-7LYX59NK.d.mts +0 -226
- package/dist/production/browser-7LYX59NK.d.mts +0 -226
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v7.
|
|
2
|
+
* react-router v7.8.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -367,6 +367,10 @@ function unstable_createContext(defaultValue) {
|
|
|
367
367
|
}
|
|
368
368
|
var _map;
|
|
369
369
|
var unstable_RouterContextProvider = class {
|
|
370
|
+
/**
|
|
371
|
+
* Create a new `unstable_RouterContextProvider` instance
|
|
372
|
+
* @param init An optional initial context map to populate the provider with
|
|
373
|
+
*/
|
|
370
374
|
constructor(init) {
|
|
371
375
|
__privateAdd(this, _map, /* @__PURE__ */ new Map());
|
|
372
376
|
if (init) {
|
|
@@ -375,6 +379,14 @@ var unstable_RouterContextProvider = class {
|
|
|
375
379
|
}
|
|
376
380
|
}
|
|
377
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Access a value from the context. If no value has been set for the context,
|
|
384
|
+
* it will return the context's `defaultValue` if provided, or throw an error
|
|
385
|
+
* if no `defaultValue` was set.
|
|
386
|
+
* @param context The context to get the value for
|
|
387
|
+
* @returns The value for the context, or the context's `defaultValue` if no
|
|
388
|
+
* value was set
|
|
389
|
+
*/
|
|
378
390
|
get(context) {
|
|
379
391
|
if (__privateGet(this, _map).has(context)) {
|
|
380
392
|
return __privateGet(this, _map).get(context);
|
|
@@ -384,6 +396,14 @@ var unstable_RouterContextProvider = class {
|
|
|
384
396
|
}
|
|
385
397
|
throw new Error("No value found for context");
|
|
386
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* Set a value for the context. If the context already has a value set, this
|
|
401
|
+
* will overwrite it.
|
|
402
|
+
*
|
|
403
|
+
* @param context The context to set the value for
|
|
404
|
+
* @param value The value to set for the context
|
|
405
|
+
* @returns {void}
|
|
406
|
+
*/
|
|
387
407
|
set(context, value) {
|
|
388
408
|
__privateGet(this, _map).set(context, value);
|
|
389
409
|
}
|
|
@@ -489,6 +509,7 @@ function convertRouteMatchToUiMatch(match, loaderData) {
|
|
|
489
509
|
pathname,
|
|
490
510
|
params,
|
|
491
511
|
data: loaderData[route.id],
|
|
512
|
+
loaderData: loaderData[route.id],
|
|
492
513
|
handle: route.handle
|
|
493
514
|
};
|
|
494
515
|
}
|
|
@@ -1434,9 +1455,7 @@ function createRouter(init) {
|
|
|
1434
1455
|
pendingNavigationController.signal,
|
|
1435
1456
|
opts && opts.submission
|
|
1436
1457
|
);
|
|
1437
|
-
let scopedContext = new unstable_RouterContextProvider(
|
|
1438
|
-
init.unstable_getContext ? await init.unstable_getContext() : void 0
|
|
1439
|
-
);
|
|
1458
|
+
let scopedContext = init.unstable_getContext ? await init.unstable_getContext() : new unstable_RouterContextProvider();
|
|
1440
1459
|
let pendingActionResult;
|
|
1441
1460
|
if (opts && opts.pendingError) {
|
|
1442
1461
|
pendingActionResult = [
|
|
@@ -1703,7 +1722,7 @@ function createRouter(init) {
|
|
|
1703
1722
|
pendingActionResult
|
|
1704
1723
|
);
|
|
1705
1724
|
pendingNavigationLoadId = ++incrementingLoadId;
|
|
1706
|
-
if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && revalidatingFetchers.length === 0) {
|
|
1725
|
+
if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && !dsMatches.some((m) => m.route.unstable_middleware) && revalidatingFetchers.length === 0) {
|
|
1707
1726
|
let updatedFetchers2 = markFetchRedirectsDone();
|
|
1708
1727
|
completeNavigation(
|
|
1709
1728
|
location,
|
|
@@ -1857,9 +1876,7 @@ function createRouter(init) {
|
|
|
1857
1876
|
setFetcherError(key, routeId, error, { flushSync });
|
|
1858
1877
|
return;
|
|
1859
1878
|
}
|
|
1860
|
-
let scopedContext = new unstable_RouterContextProvider(
|
|
1861
|
-
init.unstable_getContext ? await init.unstable_getContext() : void 0
|
|
1862
|
-
);
|
|
1879
|
+
let scopedContext = init.unstable_getContext ? await init.unstable_getContext() : new unstable_RouterContextProvider();
|
|
1863
1880
|
let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1864
1881
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
1865
1882
|
await handleFetcherAction(
|
|
@@ -2710,20 +2727,13 @@ function createStaticHandler(routes, opts) {
|
|
|
2710
2727
|
skipLoaderErrorBubbling,
|
|
2711
2728
|
skipRevalidation,
|
|
2712
2729
|
dataStrategy,
|
|
2713
|
-
|
|
2714
|
-
unstable_respond: respond
|
|
2730
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
2715
2731
|
} = {}) {
|
|
2716
2732
|
let url = new URL(request.url);
|
|
2717
2733
|
let method = request.method;
|
|
2718
2734
|
let location = createLocation("", createPath(url), null, "default");
|
|
2719
2735
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2720
2736
|
requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
|
|
2721
|
-
let respondOrStreamStaticContext = (ctx) => {
|
|
2722
|
-
return stream ? stream(
|
|
2723
|
-
requestContext,
|
|
2724
|
-
() => Promise.resolve(ctx)
|
|
2725
|
-
) : respond ? respond(ctx) : ctx;
|
|
2726
|
-
};
|
|
2727
2737
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
2728
2738
|
let error = getInternalRouterError(405, { method });
|
|
2729
2739
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -2740,7 +2750,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2740
2750
|
loaderHeaders: {},
|
|
2741
2751
|
actionHeaders: {}
|
|
2742
2752
|
};
|
|
2743
|
-
return
|
|
2753
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
2744
2754
|
} else if (!matches) {
|
|
2745
2755
|
let error = getInternalRouterError(404, { pathname: location.pathname });
|
|
2746
2756
|
let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -2757,11 +2767,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2757
2767
|
loaderHeaders: {},
|
|
2758
2768
|
actionHeaders: {}
|
|
2759
2769
|
};
|
|
2760
|
-
return
|
|
2770
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
2761
2771
|
}
|
|
2762
|
-
if (
|
|
2763
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
2764
|
-
)) {
|
|
2772
|
+
if (generateMiddlewareResponse) {
|
|
2765
2773
|
invariant(
|
|
2766
2774
|
requestContext instanceof unstable_RouterContextProvider,
|
|
2767
2775
|
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
@@ -2773,7 +2781,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2773
2781
|
mapRouteProperties2
|
|
2774
2782
|
);
|
|
2775
2783
|
let renderedStaticContext;
|
|
2776
|
-
let response = await
|
|
2784
|
+
let response = await runServerMiddlewarePipeline(
|
|
2777
2785
|
{
|
|
2778
2786
|
request,
|
|
2779
2787
|
matches,
|
|
@@ -2782,45 +2790,27 @@ function createStaticHandler(routes, opts) {
|
|
|
2782
2790
|
// this to the proper type knowing it's not an `AppLoadContext`
|
|
2783
2791
|
context: requestContext
|
|
2784
2792
|
},
|
|
2785
|
-
true,
|
|
2786
2793
|
async () => {
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
return isResponse(result3) ? result3 : { location, basename, ...result3 };
|
|
2794
|
+
let res = await generateMiddlewareResponse(
|
|
2795
|
+
async (revalidationRequest) => {
|
|
2796
|
+
let result2 = await queryImpl(
|
|
2797
|
+
revalidationRequest,
|
|
2798
|
+
location,
|
|
2799
|
+
matches,
|
|
2800
|
+
requestContext,
|
|
2801
|
+
dataStrategy || null,
|
|
2802
|
+
skipLoaderErrorBubbling === true,
|
|
2803
|
+
null,
|
|
2804
|
+
filterMatchesToLoad || null,
|
|
2805
|
+
skipRevalidation === true
|
|
2806
|
+
);
|
|
2807
|
+
if (isResponse(result2)) {
|
|
2808
|
+
return result2;
|
|
2803
2809
|
}
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
invariant(respond, "Expected respond to be defined");
|
|
2808
|
-
let result2 = await queryImpl(
|
|
2809
|
-
request,
|
|
2810
|
-
location,
|
|
2811
|
-
matches,
|
|
2812
|
-
requestContext,
|
|
2813
|
-
dataStrategy || null,
|
|
2814
|
-
skipLoaderErrorBubbling === true,
|
|
2815
|
-
null,
|
|
2816
|
-
filterMatchesToLoad || null,
|
|
2817
|
-
skipRevalidation === true
|
|
2810
|
+
renderedStaticContext = { location, basename, ...result2 };
|
|
2811
|
+
return renderedStaticContext;
|
|
2812
|
+
}
|
|
2818
2813
|
);
|
|
2819
|
-
if (isResponse(result2)) {
|
|
2820
|
-
return result2;
|
|
2821
|
-
}
|
|
2822
|
-
renderedStaticContext = { location, basename, ...result2 };
|
|
2823
|
-
let res = await respond(renderedStaticContext);
|
|
2824
2814
|
return res;
|
|
2825
2815
|
},
|
|
2826
2816
|
async (error, routeId) => {
|
|
@@ -2837,7 +2827,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2837
2827
|
error,
|
|
2838
2828
|
skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
|
|
2839
2829
|
);
|
|
2840
|
-
return
|
|
2830
|
+
return generateMiddlewareResponse(
|
|
2831
|
+
() => Promise.resolve(staticContext)
|
|
2832
|
+
);
|
|
2841
2833
|
} else {
|
|
2842
2834
|
let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
|
|
2843
2835
|
matches,
|
|
@@ -2858,7 +2850,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2858
2850
|
actionHeaders: {},
|
|
2859
2851
|
loaderHeaders: {}
|
|
2860
2852
|
};
|
|
2861
|
-
return
|
|
2853
|
+
return generateMiddlewareResponse(
|
|
2854
|
+
() => Promise.resolve(staticContext)
|
|
2855
|
+
);
|
|
2862
2856
|
}
|
|
2863
2857
|
}
|
|
2864
2858
|
);
|
|
@@ -2891,7 +2885,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2891
2885
|
routeId,
|
|
2892
2886
|
requestContext,
|
|
2893
2887
|
dataStrategy,
|
|
2894
|
-
|
|
2888
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
2895
2889
|
} = {}) {
|
|
2896
2890
|
let url = new URL(request.url);
|
|
2897
2891
|
let method = request.method;
|
|
@@ -2912,15 +2906,13 @@ function createStaticHandler(routes, opts) {
|
|
|
2912
2906
|
} else if (!match) {
|
|
2913
2907
|
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
2914
2908
|
}
|
|
2915
|
-
if (
|
|
2916
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
2917
|
-
)) {
|
|
2909
|
+
if (generateMiddlewareResponse) {
|
|
2918
2910
|
invariant(
|
|
2919
2911
|
requestContext instanceof unstable_RouterContextProvider,
|
|
2920
2912
|
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
2921
2913
|
);
|
|
2922
2914
|
await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties2);
|
|
2923
|
-
let response = await
|
|
2915
|
+
let response = await runServerMiddlewarePipeline(
|
|
2924
2916
|
{
|
|
2925
2917
|
request,
|
|
2926
2918
|
matches,
|
|
@@ -2929,37 +2921,31 @@ function createStaticHandler(routes, opts) {
|
|
|
2929
2921
|
// this to the proper type knowing it's not an `AppLoadContext`
|
|
2930
2922
|
context: requestContext
|
|
2931
2923
|
},
|
|
2932
|
-
true,
|
|
2933
2924
|
async () => {
|
|
2934
|
-
let
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2925
|
+
let res = await generateMiddlewareResponse(
|
|
2926
|
+
async (innerRequest) => {
|
|
2927
|
+
let result2 = await queryImpl(
|
|
2928
|
+
innerRequest,
|
|
2929
|
+
location,
|
|
2930
|
+
matches,
|
|
2931
|
+
requestContext,
|
|
2932
|
+
dataStrategy || null,
|
|
2933
|
+
false,
|
|
2934
|
+
match,
|
|
2935
|
+
null,
|
|
2936
|
+
false
|
|
2937
|
+
);
|
|
2938
|
+
let processed = handleQueryResult(result2);
|
|
2939
|
+
return isResponse(processed) ? processed : typeof processed === "string" ? new Response(processed) : Response.json(processed);
|
|
2940
|
+
}
|
|
2944
2941
|
);
|
|
2945
|
-
|
|
2946
|
-
return respond(result2);
|
|
2947
|
-
}
|
|
2948
|
-
let error2 = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
2949
|
-
if (error2 !== void 0) {
|
|
2950
|
-
throw error2;
|
|
2951
|
-
}
|
|
2952
|
-
let value = result2.actionData ? Object.values(result2.actionData)[0] : Object.values(result2.loaderData)[0];
|
|
2953
|
-
return typeof value === "string" ? new Response(value) : Response.json(value);
|
|
2942
|
+
return res;
|
|
2954
2943
|
},
|
|
2955
|
-
(
|
|
2956
|
-
if (isResponse(
|
|
2957
|
-
return
|
|
2944
|
+
(error) => {
|
|
2945
|
+
if (isResponse(error)) {
|
|
2946
|
+
return Promise.resolve(error);
|
|
2958
2947
|
}
|
|
2959
|
-
|
|
2960
|
-
status: 500,
|
|
2961
|
-
statusText: "Unexpected Server Error"
|
|
2962
|
-
});
|
|
2948
|
+
throw error;
|
|
2963
2949
|
}
|
|
2964
2950
|
);
|
|
2965
2951
|
return response;
|
|
@@ -2975,20 +2961,23 @@ function createStaticHandler(routes, opts) {
|
|
|
2975
2961
|
null,
|
|
2976
2962
|
false
|
|
2977
2963
|
);
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2964
|
+
return handleQueryResult(result);
|
|
2965
|
+
function handleQueryResult(result2) {
|
|
2966
|
+
if (isResponse(result2)) {
|
|
2967
|
+
return result2;
|
|
2968
|
+
}
|
|
2969
|
+
let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
2970
|
+
if (error !== void 0) {
|
|
2971
|
+
throw error;
|
|
2972
|
+
}
|
|
2973
|
+
if (result2.actionData) {
|
|
2974
|
+
return Object.values(result2.actionData)[0];
|
|
2975
|
+
}
|
|
2976
|
+
if (result2.loaderData) {
|
|
2977
|
+
return Object.values(result2.loaderData)[0];
|
|
2978
|
+
}
|
|
2979
|
+
return void 0;
|
|
2990
2980
|
}
|
|
2991
|
-
return void 0;
|
|
2992
2981
|
}
|
|
2993
2982
|
async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
|
|
2994
2983
|
invariant(
|
|
@@ -3928,45 +3917,35 @@ async function defaultDataStrategyWithMiddleware(args) {
|
|
|
3928
3917
|
if (!args.matches.some((m) => m.route.unstable_middleware)) {
|
|
3929
3918
|
return defaultDataStrategy(args);
|
|
3930
3919
|
}
|
|
3931
|
-
return
|
|
3920
|
+
return runClientMiddlewarePipeline(
|
|
3932
3921
|
args,
|
|
3933
|
-
false,
|
|
3934
3922
|
() => defaultDataStrategy(args),
|
|
3935
3923
|
(error, routeId) => ({ [routeId]: { type: "error", result: error } })
|
|
3936
3924
|
);
|
|
3937
3925
|
}
|
|
3938
|
-
async function
|
|
3926
|
+
async function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
|
3939
3927
|
let { matches, request, params, context } = args;
|
|
3940
|
-
let
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
);
|
|
3954
|
-
return propagateResult ? result : middlewareState.handlerResult;
|
|
3955
|
-
} catch (e) {
|
|
3956
|
-
if (!middlewareState.middlewareError) {
|
|
3957
|
-
throw e;
|
|
3958
|
-
}
|
|
3959
|
-
let result = await errorHandler(
|
|
3960
|
-
middlewareState.middlewareError.error,
|
|
3961
|
-
middlewareState.middlewareError.routeId
|
|
3928
|
+
let tuples = matches.flatMap(
|
|
3929
|
+
(m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
|
|
3930
|
+
);
|
|
3931
|
+
let result = await callServerRouteMiddleware(
|
|
3932
|
+
{ request, params, context },
|
|
3933
|
+
tuples,
|
|
3934
|
+
handler,
|
|
3935
|
+
errorHandler
|
|
3936
|
+
);
|
|
3937
|
+
if (isDataWithResponseInit(result)) {
|
|
3938
|
+
return new Response(
|
|
3939
|
+
typeof result.data === "string" ? result.data : JSON.stringify(result.data),
|
|
3940
|
+
{ ...result.init }
|
|
3962
3941
|
);
|
|
3963
|
-
if (propagateResult || !middlewareState.handlerResult) {
|
|
3964
|
-
return result;
|
|
3965
|
-
}
|
|
3966
|
-
return Object.assign(middlewareState.handlerResult, result);
|
|
3967
3942
|
}
|
|
3943
|
+
if (isResponse(result)) {
|
|
3944
|
+
return result;
|
|
3945
|
+
}
|
|
3946
|
+
invariant(false, `Expected a Response to be returned from route middleware`);
|
|
3968
3947
|
}
|
|
3969
|
-
async function
|
|
3948
|
+
async function callServerRouteMiddleware(args, middlewares, handler, errorHandler, idx = 0) {
|
|
3970
3949
|
let { request } = args;
|
|
3971
3950
|
if (request.signal.aborted) {
|
|
3972
3951
|
if (request.signal.reason) {
|
|
@@ -3978,8 +3957,8 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
3978
3957
|
}
|
|
3979
3958
|
let tuple = middlewares[idx];
|
|
3980
3959
|
if (!tuple) {
|
|
3981
|
-
|
|
3982
|
-
return
|
|
3960
|
+
let result = await handler();
|
|
3961
|
+
return result;
|
|
3983
3962
|
}
|
|
3984
3963
|
let [routeId, middleware] = tuple;
|
|
3985
3964
|
let nextCalled = false;
|
|
@@ -3989,17 +3968,19 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
3989
3968
|
throw new Error("You may only call `next()` once per middleware");
|
|
3990
3969
|
}
|
|
3991
3970
|
nextCalled = true;
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
if (propagateResult) {
|
|
3971
|
+
try {
|
|
3972
|
+
let result = await callServerRouteMiddleware(
|
|
3973
|
+
args,
|
|
3974
|
+
middlewares,
|
|
3975
|
+
handler,
|
|
3976
|
+
errorHandler,
|
|
3977
|
+
idx + 1
|
|
3978
|
+
);
|
|
4001
3979
|
nextResult = result;
|
|
4002
3980
|
return nextResult;
|
|
3981
|
+
} catch (e) {
|
|
3982
|
+
nextResult = await errorHandler(e, routeId);
|
|
3983
|
+
return nextResult;
|
|
4003
3984
|
}
|
|
4004
3985
|
};
|
|
4005
3986
|
try {
|
|
@@ -4012,21 +3993,92 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
4012
3993
|
next
|
|
4013
3994
|
);
|
|
4014
3995
|
if (nextCalled) {
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
return result;
|
|
4019
|
-
}
|
|
3996
|
+
return typeof result === "undefined" ? nextResult : result;
|
|
3997
|
+
} else if (isResponse(result) || isDataWithResponseInit(result)) {
|
|
3998
|
+
return result;
|
|
4020
3999
|
} else {
|
|
4021
|
-
|
|
4000
|
+
nextResult = await next();
|
|
4001
|
+
return nextResult;
|
|
4022
4002
|
}
|
|
4023
4003
|
} catch (error) {
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4004
|
+
let response = await errorHandler(error, routeId);
|
|
4005
|
+
return response;
|
|
4006
|
+
}
|
|
4007
|
+
}
|
|
4008
|
+
async function runClientMiddlewarePipeline(args, handler, errorHandler) {
|
|
4009
|
+
let { matches, request, params, context } = args;
|
|
4010
|
+
let tuples = matches.flatMap(
|
|
4011
|
+
(m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
|
|
4012
|
+
);
|
|
4013
|
+
let handlerResult = {};
|
|
4014
|
+
await callClientRouteMiddleware(
|
|
4015
|
+
{ request, params, context },
|
|
4016
|
+
tuples,
|
|
4017
|
+
handler,
|
|
4018
|
+
errorHandler,
|
|
4019
|
+
handlerResult
|
|
4020
|
+
);
|
|
4021
|
+
return handlerResult;
|
|
4022
|
+
}
|
|
4023
|
+
async function callClientRouteMiddleware(args, middlewares, handler, errorHandler, handlerResult = {}, idx = 0) {
|
|
4024
|
+
let { request } = args;
|
|
4025
|
+
if (request.signal.aborted) {
|
|
4026
|
+
if (request.signal.reason) {
|
|
4027
|
+
throw request.signal.reason;
|
|
4028
|
+
}
|
|
4029
|
+
throw new Error(
|
|
4030
|
+
`Request aborted without an \`AbortSignal.reason\`: ${request.method} ${request.url}`
|
|
4031
|
+
);
|
|
4032
|
+
}
|
|
4033
|
+
let tuple = middlewares[idx];
|
|
4034
|
+
if (!tuple) {
|
|
4035
|
+
let result = await handler();
|
|
4036
|
+
Object.assign(handlerResult, result);
|
|
4037
|
+
return;
|
|
4038
|
+
}
|
|
4039
|
+
let [routeId, middleware] = tuple;
|
|
4040
|
+
let nextCalled = false;
|
|
4041
|
+
let next = async () => {
|
|
4042
|
+
if (nextCalled) {
|
|
4043
|
+
throw new Error("You may only call `next()` once per middleware");
|
|
4044
|
+
}
|
|
4045
|
+
nextCalled = true;
|
|
4046
|
+
try {
|
|
4047
|
+
let result = await callClientRouteMiddleware(
|
|
4048
|
+
args,
|
|
4049
|
+
middlewares,
|
|
4050
|
+
handler,
|
|
4051
|
+
errorHandler,
|
|
4052
|
+
handlerResult,
|
|
4053
|
+
idx + 1
|
|
4054
|
+
);
|
|
4055
|
+
Object.assign(handlerResult, result);
|
|
4056
|
+
} catch (e) {
|
|
4057
|
+
let result = await errorHandler(e, routeId);
|
|
4058
|
+
Object.assign(handlerResult, result);
|
|
4059
|
+
}
|
|
4060
|
+
};
|
|
4061
|
+
try {
|
|
4062
|
+
let result = await middleware(
|
|
4063
|
+
{
|
|
4064
|
+
request: args.request,
|
|
4065
|
+
params: args.params,
|
|
4066
|
+
context: args.context
|
|
4067
|
+
},
|
|
4068
|
+
next
|
|
4069
|
+
);
|
|
4070
|
+
if (typeof result !== "undefined") {
|
|
4071
|
+
console.warn(
|
|
4072
|
+
"client middlewares are not intended to return values, the value will be ignored",
|
|
4073
|
+
result
|
|
4074
|
+
);
|
|
4028
4075
|
}
|
|
4029
|
-
|
|
4076
|
+
if (!nextCalled) {
|
|
4077
|
+
await next();
|
|
4078
|
+
}
|
|
4079
|
+
} catch (error) {
|
|
4080
|
+
let result = await errorHandler(error, routeId);
|
|
4081
|
+
Object.assign(handlerResult, result);
|
|
4030
4082
|
}
|
|
4031
4083
|
}
|
|
4032
4084
|
function getDataStrategyMatchLazyPromises(mapRouteProperties2, manifest, request, match, lazyRoutePropertiesToSkip) {
|
|
@@ -4137,9 +4189,8 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
4137
4189
|
);
|
|
4138
4190
|
} : (cb) => {
|
|
4139
4191
|
let typedDataStrategyArgs = dataStrategyArgs;
|
|
4140
|
-
return
|
|
4192
|
+
return runClientMiddlewarePipeline(
|
|
4141
4193
|
typedDataStrategyArgs,
|
|
4142
|
-
false,
|
|
4143
4194
|
() => cb({
|
|
4144
4195
|
...typedDataStrategyArgs,
|
|
4145
4196
|
fetcherKey,
|
|
@@ -4477,11 +4528,12 @@ function processLoaderData(state, matches, results, pendingActionResult, revalid
|
|
|
4477
4528
|
);
|
|
4478
4529
|
revalidatingFetchers.filter((f) => !f.matches || f.matches.some((m) => m.shouldLoad)).forEach((rf) => {
|
|
4479
4530
|
let { key, match, controller } = rf;
|
|
4480
|
-
let result = fetcherResults[key];
|
|
4481
|
-
invariant(result, "Did not find corresponding fetcher result");
|
|
4482
4531
|
if (controller && controller.signal.aborted) {
|
|
4483
4532
|
return;
|
|
4484
|
-
}
|
|
4533
|
+
}
|
|
4534
|
+
let result = fetcherResults[key];
|
|
4535
|
+
invariant(result, "Did not find corresponding fetcher result");
|
|
4536
|
+
if (isErrorResult(result)) {
|
|
4485
4537
|
let boundaryMatch = findNearestBoundary(state.matches, match?.route.id);
|
|
4486
4538
|
if (!(errors && errors[boundaryMatch.route.id])) {
|
|
4487
4539
|
errors = {
|
|
@@ -7147,6 +7199,12 @@ async function bubbleMiddlewareErrors(singleFetchPromise, matches, routesParams,
|
|
|
7147
7199
|
let routeResult = fetchedData.routes[match.route.id];
|
|
7148
7200
|
if ("error" in routeResult) {
|
|
7149
7201
|
middlewareError = routeResult.error;
|
|
7202
|
+
if (results[match.route.id]?.result == null) {
|
|
7203
|
+
results[match.route.id] = {
|
|
7204
|
+
type: "error",
|
|
7205
|
+
result: middlewareError
|
|
7206
|
+
};
|
|
7207
|
+
}
|
|
7150
7208
|
break;
|
|
7151
7209
|
}
|
|
7152
7210
|
}
|
|
@@ -8150,12 +8208,14 @@ function getManifestPath(_manifestPath, basename) {
|
|
|
8150
8208
|
}
|
|
8151
8209
|
var MANIFEST_VERSION_STORAGE_KEY = "react-router-manifest-version";
|
|
8152
8210
|
async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, manifestPath, patchRoutes, signal) {
|
|
8211
|
+
const searchParams = new URLSearchParams();
|
|
8212
|
+
paths.sort().forEach((path) => searchParams.append("p", path));
|
|
8213
|
+
searchParams.set("version", manifest.version);
|
|
8153
8214
|
let url = new URL(
|
|
8154
8215
|
getManifestPath(manifestPath, basename),
|
|
8155
8216
|
window.location.origin
|
|
8156
8217
|
);
|
|
8157
|
-
|
|
8158
|
-
url.searchParams.set("version", manifest.version);
|
|
8218
|
+
url.search = searchParams.toString();
|
|
8159
8219
|
if (url.toString().length > URL_LIMIT) {
|
|
8160
8220
|
nextPaths.clear();
|
|
8161
8221
|
return;
|
|
@@ -8333,7 +8393,7 @@ function getActiveMatches(matches, errors, isSpaMode) {
|
|
|
8333
8393
|
return matches;
|
|
8334
8394
|
}
|
|
8335
8395
|
var CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
|
|
8336
|
-
function Links() {
|
|
8396
|
+
function Links({ nonce }) {
|
|
8337
8397
|
let { isSpaMode, manifest, routeModules, criticalCss } = useFrameworkContext();
|
|
8338
8398
|
let { errors, matches: routerMatches } = useDataRouterStateContext();
|
|
8339
8399
|
let matches = getActiveMatches(routerMatches, errors, isSpaMode);
|
|
@@ -8352,10 +8412,11 @@ function Links() {
|
|
|
8352
8412
|
{
|
|
8353
8413
|
...{ [CRITICAL_CSS_DATA_ATTRIBUTE]: "" },
|
|
8354
8414
|
rel: "stylesheet",
|
|
8355
|
-
href: criticalCss.href
|
|
8415
|
+
href: criticalCss.href,
|
|
8416
|
+
nonce
|
|
8356
8417
|
}
|
|
8357
8418
|
) : null, keyedLinks.map(
|
|
8358
|
-
({ key, link }) => isPageLinkDescriptor(link) ? /* @__PURE__ */ React8.createElement(PrefetchPageLinks, { key, ...link }) : /* @__PURE__ */ React8.createElement("link", { key, ...link })
|
|
8419
|
+
({ key, link }) => isPageLinkDescriptor(link) ? /* @__PURE__ */ React8.createElement(PrefetchPageLinks, { key, nonce, ...link }) : /* @__PURE__ */ React8.createElement("link", { key, nonce, ...link })
|
|
8359
8420
|
));
|
|
8360
8421
|
}
|
|
8361
8422
|
function PrefetchPageLinks({ page, ...linkProps }) {
|
|
@@ -8466,7 +8527,7 @@ function PrefetchPageLinksImpl({
|
|
|
8466
8527
|
return /* @__PURE__ */ React8.createElement(React8.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React8.createElement("link", { key: href, rel: "prefetch", as: "fetch", href, ...linkProps })), moduleHrefs.map((href) => /* @__PURE__ */ React8.createElement("link", { key: href, rel: "modulepreload", href, ...linkProps })), keyedPrefetchLinks.map(({ key, link }) => (
|
|
8467
8528
|
// these don't spread `linkProps` because they are full link descriptors
|
|
8468
8529
|
// already with their own props
|
|
8469
|
-
/* @__PURE__ */ React8.createElement("link", { key, ...link })
|
|
8530
|
+
/* @__PURE__ */ React8.createElement("link", { key, nonce: linkProps.nonce, ...link })
|
|
8470
8531
|
)));
|
|
8471
8532
|
}
|
|
8472
8533
|
function Meta() {
|
|
@@ -8495,6 +8556,7 @@ function Meta() {
|
|
|
8495
8556
|
let match = {
|
|
8496
8557
|
id: routeId,
|
|
8497
8558
|
data: data2,
|
|
8559
|
+
loaderData: data2,
|
|
8498
8560
|
meta: [],
|
|
8499
8561
|
params: _match.params,
|
|
8500
8562
|
pathname: _match.pathname,
|
|
@@ -8505,6 +8567,7 @@ function Meta() {
|
|
|
8505
8567
|
if (routeModule?.meta) {
|
|
8506
8568
|
routeMeta = typeof routeModule.meta === "function" ? routeModule.meta({
|
|
8507
8569
|
data: data2,
|
|
8570
|
+
loaderData: data2,
|
|
8508
8571
|
params,
|
|
8509
8572
|
location,
|
|
8510
8573
|
matches,
|
|
@@ -8845,7 +8908,7 @@ var isBrowser = typeof window !== "undefined" && typeof window.document !== "und
|
|
|
8845
8908
|
try {
|
|
8846
8909
|
if (isBrowser) {
|
|
8847
8910
|
window.__reactRouterVersion = // @ts-expect-error
|
|
8848
|
-
"7.
|
|
8911
|
+
"7.8.0-pre.0";
|
|
8849
8912
|
}
|
|
8850
8913
|
} catch (e) {
|
|
8851
8914
|
}
|