react-router 0.0.0-experimental-2a6c7bc → 0.0.0-experimental-e89ad3012
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/dist/development/{chunk-VEWXUMGM.mjs → chunk-3O4L5GVQ.mjs} +90 -125
- package/dist/development/{chunk-JRLTRGBE.js → chunk-JJHCVRDZ.js} +89 -124
- package/dist/development/{chunk-GSZ4XTPZ.js → chunk-ROJMZUUV.js} +130 -130
- package/dist/{production/chunk-ATNMTWNA.mjs → development/chunk-XKV32KFX.mjs} +157 -141
- package/dist/development/{components-CFzgj3gZ.d.mts → components-BkK38HPd.d.mts} +16 -16
- package/dist/development/{context-AvZz33Zq.d.mts → context-CphUWOpx.d.mts} +238 -22
- package/dist/development/dom-export.d.mts +3 -3
- package/dist/development/dom-export.d.ts +1 -1
- package/dist/development/dom-export.js +3 -3
- package/dist/development/dom-export.mjs +3 -3
- package/dist/{production/index-react-server-client-DIZWnqdE.d.ts → development/index-react-server-client-D-lyvxf_.d.ts} +25 -26
- package/dist/{production/index-react-server-client-BuCmY0hu.d.mts → development/index-react-server-client-pe1TAKAq.d.mts} +12 -13
- package/dist/development/index-react-server-client.d.mts +4 -4
- 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 +193 -14
- package/dist/development/index-react-server.d.ts +193 -14
- package/dist/development/index-react-server.js +115 -147
- package/dist/development/index-react-server.mjs +115 -147
- package/dist/development/index.d.mts +8 -8
- package/dist/development/index.d.ts +4 -4
- package/dist/development/index.js +240 -224
- package/dist/development/index.mjs +3 -3
- package/dist/development/lib/types/internal.d.mts +2 -2
- package/dist/development/lib/types/internal.d.ts +1 -1
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/development/{route-data-BnrIwdAP.d.mts → route-data-DJXZgnJq.d.mts} +1 -1
- package/dist/development/{routeModules-BbH0xTnc.d.ts → routeModules-DH3xUx4Z.d.ts} +238 -22
- package/dist/{development/chunk-M2KD4YIT.mjs → production/chunk-J6PLTU3O.mjs} +157 -141
- package/dist/production/{chunk-3UOGQQWX.js → chunk-NFNPXIQE.js} +89 -124
- package/dist/production/{chunk-P2JVUBYL.mjs → chunk-QI3NR5VQ.mjs} +90 -125
- package/dist/production/{chunk-ZIOZTUIH.js → chunk-X3M2F3OK.js} +130 -130
- package/dist/production/{components-CFzgj3gZ.d.mts → components-BkK38HPd.d.mts} +16 -16
- package/dist/production/{context-AvZz33Zq.d.mts → context-CphUWOpx.d.mts} +238 -22
- package/dist/production/dom-export.d.mts +3 -3
- package/dist/production/dom-export.d.ts +1 -1
- package/dist/production/dom-export.js +3 -3
- package/dist/production/dom-export.mjs +3 -3
- package/dist/{development/index-react-server-client-DIZWnqdE.d.ts → production/index-react-server-client-D-lyvxf_.d.ts} +25 -26
- package/dist/{development/index-react-server-client-BuCmY0hu.d.mts → production/index-react-server-client-pe1TAKAq.d.mts} +12 -13
- package/dist/production/index-react-server-client.d.mts +4 -4
- 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 +193 -14
- package/dist/production/index-react-server.d.ts +193 -14
- package/dist/production/index-react-server.js +115 -147
- package/dist/production/index-react-server.mjs +115 -147
- package/dist/production/index.d.mts +8 -8
- package/dist/production/index.d.ts +4 -4
- package/dist/production/index.js +240 -224
- package/dist/production/index.mjs +3 -3
- package/dist/production/lib/types/internal.d.mts +2 -2
- package/dist/production/lib/types/internal.d.ts +1 -1
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/production/{route-data-BnrIwdAP.d.mts → route-data-DJXZgnJq.d.mts} +1 -1
- package/dist/production/{routeModules-BbH0xTnc.d.ts → routeModules-DH3xUx4Z.d.ts} +238 -22
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v0.0.0-experimental-
|
|
2
|
+
* react-router v0.0.0-experimental-e89ad3012
|
|
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
|
|
384
|
+
* context, it will return the context's `defaultValue` if provided, or throw an
|
|
385
|
+
* error if no `defaultValue` was set.
|
|
386
|
+
* @param context The context to get the value for
|
|
387
|
+
* @returns The value for the context, or the contexts `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,
|
|
401
|
+
* this 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
|
}
|
|
@@ -1702,7 +1722,7 @@ function createRouter(init) {
|
|
|
1702
1722
|
pendingActionResult
|
|
1703
1723
|
);
|
|
1704
1724
|
pendingNavigationLoadId = ++incrementingLoadId;
|
|
1705
|
-
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) {
|
|
1706
1726
|
let updatedFetchers2 = markFetchRedirectsDone();
|
|
1707
1727
|
completeNavigation(
|
|
1708
1728
|
location,
|
|
@@ -2707,20 +2727,13 @@ function createStaticHandler(routes, opts) {
|
|
|
2707
2727
|
skipLoaderErrorBubbling,
|
|
2708
2728
|
skipRevalidation,
|
|
2709
2729
|
dataStrategy,
|
|
2710
|
-
|
|
2711
|
-
unstable_respond: respond
|
|
2730
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
2712
2731
|
} = {}) {
|
|
2713
2732
|
let url = new URL(request.url);
|
|
2714
2733
|
let method = request.method;
|
|
2715
2734
|
let location = createLocation("", createPath(url), null, "default");
|
|
2716
2735
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2717
2736
|
requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
|
|
2718
|
-
let shortCircuitResult = (ctx) => {
|
|
2719
|
-
return stream ? stream(
|
|
2720
|
-
requestContext,
|
|
2721
|
-
() => Promise.resolve(ctx)
|
|
2722
|
-
) : respond ? respond(ctx) : ctx;
|
|
2723
|
-
};
|
|
2724
2737
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
2725
2738
|
let error = getInternalRouterError(405, { method });
|
|
2726
2739
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -2737,7 +2750,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2737
2750
|
loaderHeaders: {},
|
|
2738
2751
|
actionHeaders: {}
|
|
2739
2752
|
};
|
|
2740
|
-
return
|
|
2753
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
2741
2754
|
} else if (!matches) {
|
|
2742
2755
|
let error = getInternalRouterError(404, { pathname: location.pathname });
|
|
2743
2756
|
let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -2754,11 +2767,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2754
2767
|
loaderHeaders: {},
|
|
2755
2768
|
actionHeaders: {}
|
|
2756
2769
|
};
|
|
2757
|
-
return
|
|
2770
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
2758
2771
|
}
|
|
2759
|
-
if (
|
|
2760
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
2761
|
-
)) {
|
|
2772
|
+
if (generateMiddlewareResponse) {
|
|
2762
2773
|
invariant(
|
|
2763
2774
|
requestContext instanceof unstable_RouterContextProvider,
|
|
2764
2775
|
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
@@ -2781,43 +2792,26 @@ function createStaticHandler(routes, opts) {
|
|
|
2781
2792
|
},
|
|
2782
2793
|
true,
|
|
2783
2794
|
async () => {
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
return isResponse(result3) ? result3 : { location, basename, ...result3 };
|
|
2795
|
+
let res = await generateMiddlewareResponse(
|
|
2796
|
+
async (revalidationRequest) => {
|
|
2797
|
+
let result2 = await queryImpl(
|
|
2798
|
+
revalidationRequest,
|
|
2799
|
+
location,
|
|
2800
|
+
matches,
|
|
2801
|
+
requestContext,
|
|
2802
|
+
dataStrategy || null,
|
|
2803
|
+
skipLoaderErrorBubbling === true,
|
|
2804
|
+
null,
|
|
2805
|
+
filterMatchesToLoad || null,
|
|
2806
|
+
skipRevalidation === true
|
|
2807
|
+
);
|
|
2808
|
+
if (isResponse(result2)) {
|
|
2809
|
+
return result2;
|
|
2800
2810
|
}
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
invariant(respond, "Expected respond to be defined");
|
|
2805
|
-
let result2 = await queryImpl(
|
|
2806
|
-
request,
|
|
2807
|
-
location,
|
|
2808
|
-
matches,
|
|
2809
|
-
requestContext,
|
|
2810
|
-
dataStrategy || null,
|
|
2811
|
-
skipLoaderErrorBubbling === true,
|
|
2812
|
-
null,
|
|
2813
|
-
filterMatchesToLoad || null,
|
|
2814
|
-
skipRevalidation === true
|
|
2811
|
+
renderedStaticContext = { location, basename, ...result2 };
|
|
2812
|
+
return renderedStaticContext;
|
|
2813
|
+
}
|
|
2815
2814
|
);
|
|
2816
|
-
if (isResponse(result2)) {
|
|
2817
|
-
return result2;
|
|
2818
|
-
}
|
|
2819
|
-
renderedStaticContext = { location, basename, ...result2 };
|
|
2820
|
-
let res = await respond(renderedStaticContext);
|
|
2821
2815
|
return res;
|
|
2822
2816
|
},
|
|
2823
2817
|
async (error, routeId) => {
|
|
@@ -2834,7 +2828,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2834
2828
|
error,
|
|
2835
2829
|
skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
|
|
2836
2830
|
);
|
|
2837
|
-
return
|
|
2831
|
+
return generateMiddlewareResponse(
|
|
2832
|
+
() => Promise.resolve(staticContext)
|
|
2833
|
+
);
|
|
2838
2834
|
} else {
|
|
2839
2835
|
let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
|
|
2840
2836
|
matches,
|
|
@@ -2855,7 +2851,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2855
2851
|
actionHeaders: {},
|
|
2856
2852
|
loaderHeaders: {}
|
|
2857
2853
|
};
|
|
2858
|
-
return
|
|
2854
|
+
return generateMiddlewareResponse(
|
|
2855
|
+
() => Promise.resolve(staticContext)
|
|
2856
|
+
);
|
|
2859
2857
|
}
|
|
2860
2858
|
}
|
|
2861
2859
|
);
|
|
@@ -2888,8 +2886,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2888
2886
|
routeId,
|
|
2889
2887
|
requestContext,
|
|
2890
2888
|
dataStrategy,
|
|
2891
|
-
|
|
2892
|
-
unstable_stream: stream
|
|
2889
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
2893
2890
|
} = {}) {
|
|
2894
2891
|
let url = new URL(request.url);
|
|
2895
2892
|
let method = request.method;
|
|
@@ -2910,9 +2907,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2910
2907
|
} else if (!match) {
|
|
2911
2908
|
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
2912
2909
|
}
|
|
2913
|
-
if (
|
|
2914
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
2915
|
-
)) {
|
|
2910
|
+
if (generateMiddlewareResponse) {
|
|
2916
2911
|
invariant(
|
|
2917
2912
|
requestContext instanceof unstable_RouterContextProvider,
|
|
2918
2913
|
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
@@ -2929,63 +2924,30 @@ function createStaticHandler(routes, opts) {
|
|
|
2929
2924
|
},
|
|
2930
2925
|
true,
|
|
2931
2926
|
async () => {
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
return result3;
|
|
2949
|
-
}
|
|
2950
|
-
let error3 = result3.errors ? Object.values(result3.errors)[0] : void 0;
|
|
2951
|
-
if (error3 !== void 0) {
|
|
2952
|
-
throw error3;
|
|
2953
|
-
}
|
|
2954
|
-
let value2 = result3.actionData ? Object.values(result3.actionData)[0] : Object.values(result3.loaderData)[0];
|
|
2955
|
-
return typeof value2 === "string" ? new Response(value2) : Response.json(value2);
|
|
2956
|
-
}
|
|
2957
|
-
);
|
|
2958
|
-
return res;
|
|
2959
|
-
}
|
|
2960
|
-
invariant(respond, "Expected respond to be defined");
|
|
2961
|
-
let result2 = await queryImpl(
|
|
2962
|
-
request,
|
|
2963
|
-
location,
|
|
2964
|
-
matches,
|
|
2965
|
-
requestContext,
|
|
2966
|
-
dataStrategy || null,
|
|
2967
|
-
false,
|
|
2968
|
-
match,
|
|
2969
|
-
null,
|
|
2970
|
-
false
|
|
2971
|
-
);
|
|
2972
|
-
if (isResponse(result2)) {
|
|
2973
|
-
return respond(result2);
|
|
2974
|
-
}
|
|
2975
|
-
let error2 = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
2976
|
-
if (error2 !== void 0) {
|
|
2977
|
-
throw error2;
|
|
2978
|
-
}
|
|
2979
|
-
let value = result2.actionData ? Object.values(result2.actionData)[0] : Object.values(result2.loaderData)[0];
|
|
2980
|
-
return respond(
|
|
2981
|
-
typeof value === "string" ? new Response(value) : Response.json(value)
|
|
2927
|
+
let res = await generateMiddlewareResponse(
|
|
2928
|
+
async (innerRequest) => {
|
|
2929
|
+
let result2 = await queryImpl(
|
|
2930
|
+
innerRequest,
|
|
2931
|
+
location,
|
|
2932
|
+
matches,
|
|
2933
|
+
requestContext,
|
|
2934
|
+
dataStrategy || null,
|
|
2935
|
+
false,
|
|
2936
|
+
match,
|
|
2937
|
+
null,
|
|
2938
|
+
false
|
|
2939
|
+
);
|
|
2940
|
+
let processed = handleQueryResult(result2);
|
|
2941
|
+
return isResponse(processed) ? processed : typeof processed === "string" ? new Response(processed) : Response.json(processed);
|
|
2942
|
+
}
|
|
2982
2943
|
);
|
|
2944
|
+
return res;
|
|
2983
2945
|
},
|
|
2984
|
-
(
|
|
2985
|
-
if (isResponse(
|
|
2986
|
-
return
|
|
2946
|
+
(error) => {
|
|
2947
|
+
if (isResponse(error)) {
|
|
2948
|
+
return error;
|
|
2987
2949
|
}
|
|
2988
|
-
throw
|
|
2950
|
+
throw error;
|
|
2989
2951
|
}
|
|
2990
2952
|
);
|
|
2991
2953
|
return response;
|
|
@@ -3001,20 +2963,23 @@ function createStaticHandler(routes, opts) {
|
|
|
3001
2963
|
null,
|
|
3002
2964
|
false
|
|
3003
2965
|
);
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
2966
|
+
return handleQueryResult(result);
|
|
2967
|
+
function handleQueryResult(result2) {
|
|
2968
|
+
if (isResponse(result2)) {
|
|
2969
|
+
return result2;
|
|
2970
|
+
}
|
|
2971
|
+
let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
2972
|
+
if (error !== void 0) {
|
|
2973
|
+
throw error;
|
|
2974
|
+
}
|
|
2975
|
+
if (result2.actionData) {
|
|
2976
|
+
return Object.values(result2.actionData)[0];
|
|
2977
|
+
}
|
|
2978
|
+
if (result2.loaderData) {
|
|
2979
|
+
return Object.values(result2.loaderData)[0];
|
|
2980
|
+
}
|
|
2981
|
+
return void 0;
|
|
3016
2982
|
}
|
|
3017
|
-
return void 0;
|
|
3018
2983
|
}
|
|
3019
2984
|
async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
|
|
3020
2985
|
invariant(
|
|
@@ -8902,7 +8867,7 @@ var isBrowser = typeof window !== "undefined" && typeof window.document !== "und
|
|
|
8902
8867
|
try {
|
|
8903
8868
|
if (isBrowser) {
|
|
8904
8869
|
window.__reactRouterVersion = // @ts-expect-error
|
|
8905
|
-
"0.0.0-experimental-
|
|
8870
|
+
"0.0.0-experimental-e89ad3012";
|
|
8906
8871
|
}
|
|
8907
8872
|
} catch (e) {
|
|
8908
8873
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
|
|
2
|
-
* react-router v0.0.0-experimental-
|
|
2
|
+
* react-router v0.0.0-experimental-e89ad3012
|
|
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
|
|
384
|
+
* context, it will return the context's `defaultValue` if provided, or throw an
|
|
385
|
+
* error if no `defaultValue` was set.
|
|
386
|
+
* @param context The context to get the value for
|
|
387
|
+
* @returns The value for the context, or the contexts `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,
|
|
401
|
+
* this 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
|
}
|
|
@@ -1702,7 +1722,7 @@ function createRouter(init) {
|
|
|
1702
1722
|
pendingActionResult
|
|
1703
1723
|
);
|
|
1704
1724
|
pendingNavigationLoadId = ++incrementingLoadId;
|
|
1705
|
-
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) {
|
|
1706
1726
|
let updatedFetchers2 = markFetchRedirectsDone();
|
|
1707
1727
|
completeNavigation(
|
|
1708
1728
|
location,
|
|
@@ -2707,20 +2727,13 @@ function createStaticHandler(routes, opts) {
|
|
|
2707
2727
|
skipLoaderErrorBubbling,
|
|
2708
2728
|
skipRevalidation,
|
|
2709
2729
|
dataStrategy,
|
|
2710
|
-
|
|
2711
|
-
unstable_respond: respond
|
|
2730
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
2712
2731
|
} = {}) {
|
|
2713
2732
|
let url = new URL(request.url);
|
|
2714
2733
|
let method = request.method;
|
|
2715
2734
|
let location = createLocation("", createPath(url), null, "default");
|
|
2716
2735
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2717
2736
|
requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
|
|
2718
|
-
let shortCircuitResult = (ctx) => {
|
|
2719
|
-
return stream ? stream(
|
|
2720
|
-
requestContext,
|
|
2721
|
-
() => Promise.resolve(ctx)
|
|
2722
|
-
) : respond ? respond(ctx) : ctx;
|
|
2723
|
-
};
|
|
2724
2737
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
2725
2738
|
let error = getInternalRouterError(405, { method });
|
|
2726
2739
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -2737,7 +2750,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2737
2750
|
loaderHeaders: {},
|
|
2738
2751
|
actionHeaders: {}
|
|
2739
2752
|
};
|
|
2740
|
-
return
|
|
2753
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
2741
2754
|
} else if (!matches) {
|
|
2742
2755
|
let error = getInternalRouterError(404, { pathname: location.pathname });
|
|
2743
2756
|
let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -2754,11 +2767,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2754
2767
|
loaderHeaders: {},
|
|
2755
2768
|
actionHeaders: {}
|
|
2756
2769
|
};
|
|
2757
|
-
return
|
|
2770
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
2758
2771
|
}
|
|
2759
|
-
if (
|
|
2760
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
2761
|
-
)) {
|
|
2772
|
+
if (generateMiddlewareResponse) {
|
|
2762
2773
|
invariant(
|
|
2763
2774
|
requestContext instanceof unstable_RouterContextProvider,
|
|
2764
2775
|
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
@@ -2781,43 +2792,26 @@ function createStaticHandler(routes, opts) {
|
|
|
2781
2792
|
},
|
|
2782
2793
|
true,
|
|
2783
2794
|
async () => {
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
return isResponse(result3) ? result3 : { location, basename, ...result3 };
|
|
2795
|
+
let res = await generateMiddlewareResponse(
|
|
2796
|
+
async (revalidationRequest) => {
|
|
2797
|
+
let result2 = await queryImpl(
|
|
2798
|
+
revalidationRequest,
|
|
2799
|
+
location,
|
|
2800
|
+
matches,
|
|
2801
|
+
requestContext,
|
|
2802
|
+
dataStrategy || null,
|
|
2803
|
+
skipLoaderErrorBubbling === true,
|
|
2804
|
+
null,
|
|
2805
|
+
filterMatchesToLoad || null,
|
|
2806
|
+
skipRevalidation === true
|
|
2807
|
+
);
|
|
2808
|
+
if (isResponse(result2)) {
|
|
2809
|
+
return result2;
|
|
2800
2810
|
}
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
invariant(respond, "Expected respond to be defined");
|
|
2805
|
-
let result2 = await queryImpl(
|
|
2806
|
-
request,
|
|
2807
|
-
location,
|
|
2808
|
-
matches,
|
|
2809
|
-
requestContext,
|
|
2810
|
-
dataStrategy || null,
|
|
2811
|
-
skipLoaderErrorBubbling === true,
|
|
2812
|
-
null,
|
|
2813
|
-
filterMatchesToLoad || null,
|
|
2814
|
-
skipRevalidation === true
|
|
2811
|
+
renderedStaticContext = { location, basename, ...result2 };
|
|
2812
|
+
return renderedStaticContext;
|
|
2813
|
+
}
|
|
2815
2814
|
);
|
|
2816
|
-
if (isResponse(result2)) {
|
|
2817
|
-
return result2;
|
|
2818
|
-
}
|
|
2819
|
-
renderedStaticContext = { location, basename, ...result2 };
|
|
2820
|
-
let res = await respond(renderedStaticContext);
|
|
2821
2815
|
return res;
|
|
2822
2816
|
},
|
|
2823
2817
|
async (error, routeId) => {
|
|
@@ -2834,7 +2828,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2834
2828
|
error,
|
|
2835
2829
|
skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
|
|
2836
2830
|
);
|
|
2837
|
-
return
|
|
2831
|
+
return generateMiddlewareResponse(
|
|
2832
|
+
() => Promise.resolve(staticContext)
|
|
2833
|
+
);
|
|
2838
2834
|
} else {
|
|
2839
2835
|
let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
|
|
2840
2836
|
matches,
|
|
@@ -2855,7 +2851,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2855
2851
|
actionHeaders: {},
|
|
2856
2852
|
loaderHeaders: {}
|
|
2857
2853
|
};
|
|
2858
|
-
return
|
|
2854
|
+
return generateMiddlewareResponse(
|
|
2855
|
+
() => Promise.resolve(staticContext)
|
|
2856
|
+
);
|
|
2859
2857
|
}
|
|
2860
2858
|
}
|
|
2861
2859
|
);
|
|
@@ -2888,8 +2886,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2888
2886
|
routeId,
|
|
2889
2887
|
requestContext,
|
|
2890
2888
|
dataStrategy,
|
|
2891
|
-
|
|
2892
|
-
unstable_stream: stream
|
|
2889
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
2893
2890
|
} = {}) {
|
|
2894
2891
|
let url = new URL(request.url);
|
|
2895
2892
|
let method = request.method;
|
|
@@ -2910,9 +2907,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2910
2907
|
} else if (!match) {
|
|
2911
2908
|
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
2912
2909
|
}
|
|
2913
|
-
if (
|
|
2914
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
2915
|
-
)) {
|
|
2910
|
+
if (generateMiddlewareResponse) {
|
|
2916
2911
|
invariant(
|
|
2917
2912
|
requestContext instanceof unstable_RouterContextProvider,
|
|
2918
2913
|
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
@@ -2929,63 +2924,30 @@ function createStaticHandler(routes, opts) {
|
|
|
2929
2924
|
},
|
|
2930
2925
|
true,
|
|
2931
2926
|
async () => {
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
return result3;
|
|
2949
|
-
}
|
|
2950
|
-
let error3 = result3.errors ? Object.values(result3.errors)[0] : void 0;
|
|
2951
|
-
if (error3 !== void 0) {
|
|
2952
|
-
throw error3;
|
|
2953
|
-
}
|
|
2954
|
-
let value2 = result3.actionData ? Object.values(result3.actionData)[0] : Object.values(result3.loaderData)[0];
|
|
2955
|
-
return typeof value2 === "string" ? new Response(value2) : Response.json(value2);
|
|
2956
|
-
}
|
|
2957
|
-
);
|
|
2958
|
-
return res;
|
|
2959
|
-
}
|
|
2960
|
-
invariant(respond, "Expected respond to be defined");
|
|
2961
|
-
let result2 = await queryImpl(
|
|
2962
|
-
request,
|
|
2963
|
-
location,
|
|
2964
|
-
matches,
|
|
2965
|
-
requestContext,
|
|
2966
|
-
dataStrategy || null,
|
|
2967
|
-
false,
|
|
2968
|
-
match,
|
|
2969
|
-
null,
|
|
2970
|
-
false
|
|
2971
|
-
);
|
|
2972
|
-
if (isResponse(result2)) {
|
|
2973
|
-
return respond(result2);
|
|
2974
|
-
}
|
|
2975
|
-
let error2 = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
2976
|
-
if (error2 !== void 0) {
|
|
2977
|
-
throw error2;
|
|
2978
|
-
}
|
|
2979
|
-
let value = result2.actionData ? Object.values(result2.actionData)[0] : Object.values(result2.loaderData)[0];
|
|
2980
|
-
return respond(
|
|
2981
|
-
typeof value === "string" ? new Response(value) : Response.json(value)
|
|
2927
|
+
let res = await generateMiddlewareResponse(
|
|
2928
|
+
async (innerRequest) => {
|
|
2929
|
+
let result2 = await queryImpl(
|
|
2930
|
+
innerRequest,
|
|
2931
|
+
location,
|
|
2932
|
+
matches,
|
|
2933
|
+
requestContext,
|
|
2934
|
+
dataStrategy || null,
|
|
2935
|
+
false,
|
|
2936
|
+
match,
|
|
2937
|
+
null,
|
|
2938
|
+
false
|
|
2939
|
+
);
|
|
2940
|
+
let processed = handleQueryResult(result2);
|
|
2941
|
+
return isResponse(processed) ? processed : typeof processed === "string" ? new Response(processed) : Response.json(processed);
|
|
2942
|
+
}
|
|
2982
2943
|
);
|
|
2944
|
+
return res;
|
|
2983
2945
|
},
|
|
2984
|
-
(
|
|
2985
|
-
if (isResponse(
|
|
2986
|
-
return
|
|
2946
|
+
(error) => {
|
|
2947
|
+
if (isResponse(error)) {
|
|
2948
|
+
return error;
|
|
2987
2949
|
}
|
|
2988
|
-
throw
|
|
2950
|
+
throw error;
|
|
2989
2951
|
}
|
|
2990
2952
|
);
|
|
2991
2953
|
return response;
|
|
@@ -3001,20 +2963,23 @@ function createStaticHandler(routes, opts) {
|
|
|
3001
2963
|
null,
|
|
3002
2964
|
false
|
|
3003
2965
|
);
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
2966
|
+
return handleQueryResult(result);
|
|
2967
|
+
function handleQueryResult(result2) {
|
|
2968
|
+
if (isResponse(result2)) {
|
|
2969
|
+
return result2;
|
|
2970
|
+
}
|
|
2971
|
+
let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
2972
|
+
if (error !== void 0) {
|
|
2973
|
+
throw error;
|
|
2974
|
+
}
|
|
2975
|
+
if (result2.actionData) {
|
|
2976
|
+
return Object.values(result2.actionData)[0];
|
|
2977
|
+
}
|
|
2978
|
+
if (result2.loaderData) {
|
|
2979
|
+
return Object.values(result2.loaderData)[0];
|
|
2980
|
+
}
|
|
2981
|
+
return void 0;
|
|
3016
2982
|
}
|
|
3017
|
-
return void 0;
|
|
3018
2983
|
}
|
|
3019
2984
|
async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
|
|
3020
2985
|
invariant(
|