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
|
@@ -6,7 +6,7 @@ export { Await, BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta
|
|
|
6
6
|
import { serialize, parse } from 'cookie';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* react-router v7.
|
|
9
|
+
* react-router v7.8.0-pre.0
|
|
10
10
|
*
|
|
11
11
|
* Copyright (c) Remix Software Inc.
|
|
12
12
|
*
|
|
@@ -92,6 +92,10 @@ function unstable_createContext(defaultValue) {
|
|
|
92
92
|
}
|
|
93
93
|
var _map;
|
|
94
94
|
var unstable_RouterContextProvider = class {
|
|
95
|
+
/**
|
|
96
|
+
* Create a new `unstable_RouterContextProvider` instance
|
|
97
|
+
* @param init An optional initial context map to populate the provider with
|
|
98
|
+
*/
|
|
95
99
|
constructor(init) {
|
|
96
100
|
__privateAdd(this, _map, /* @__PURE__ */ new Map());
|
|
97
101
|
if (init) {
|
|
@@ -100,6 +104,14 @@ var unstable_RouterContextProvider = class {
|
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Access a value from the context. If no value has been set for the context,
|
|
109
|
+
* it will return the context's `defaultValue` if provided, or throw an error
|
|
110
|
+
* if no `defaultValue` was set.
|
|
111
|
+
* @param context The context to get the value for
|
|
112
|
+
* @returns The value for the context, or the context's `defaultValue` if no
|
|
113
|
+
* value was set
|
|
114
|
+
*/
|
|
103
115
|
get(context) {
|
|
104
116
|
if (__privateGet(this, _map).has(context)) {
|
|
105
117
|
return __privateGet(this, _map).get(context);
|
|
@@ -109,6 +121,14 @@ var unstable_RouterContextProvider = class {
|
|
|
109
121
|
}
|
|
110
122
|
throw new Error("No value found for context");
|
|
111
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Set a value for the context. If the context already has a value set, this
|
|
126
|
+
* will overwrite it.
|
|
127
|
+
*
|
|
128
|
+
* @param context The context to set the value for
|
|
129
|
+
* @param value The value to set for the context
|
|
130
|
+
* @returns {void}
|
|
131
|
+
*/
|
|
112
132
|
set(context, value) {
|
|
113
133
|
__privateGet(this, _map).set(context, value);
|
|
114
134
|
}
|
|
@@ -214,6 +234,7 @@ function convertRouteMatchToUiMatch(match, loaderData) {
|
|
|
214
234
|
pathname,
|
|
215
235
|
params,
|
|
216
236
|
data: loaderData[route.id],
|
|
237
|
+
loaderData: loaderData[route.id],
|
|
217
238
|
handle: route.handle
|
|
218
239
|
};
|
|
219
240
|
}
|
|
@@ -644,20 +665,13 @@ function createStaticHandler(routes, opts) {
|
|
|
644
665
|
skipLoaderErrorBubbling,
|
|
645
666
|
skipRevalidation,
|
|
646
667
|
dataStrategy,
|
|
647
|
-
|
|
648
|
-
unstable_respond: respond
|
|
668
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
649
669
|
} = {}) {
|
|
650
670
|
let url = new URL(request.url);
|
|
651
671
|
let method = request.method;
|
|
652
672
|
let location = createLocation("", createPath(url), null, "default");
|
|
653
673
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
654
674
|
requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
|
|
655
|
-
let respondOrStreamStaticContext = (ctx) => {
|
|
656
|
-
return stream ? stream(
|
|
657
|
-
requestContext,
|
|
658
|
-
() => Promise.resolve(ctx)
|
|
659
|
-
) : respond ? respond(ctx) : ctx;
|
|
660
|
-
};
|
|
661
675
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
662
676
|
let error = getInternalRouterError(405, { method });
|
|
663
677
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -674,7 +688,7 @@ function createStaticHandler(routes, opts) {
|
|
|
674
688
|
loaderHeaders: {},
|
|
675
689
|
actionHeaders: {}
|
|
676
690
|
};
|
|
677
|
-
return
|
|
691
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
678
692
|
} else if (!matches) {
|
|
679
693
|
let error = getInternalRouterError(404, { pathname: location.pathname });
|
|
680
694
|
let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -691,11 +705,9 @@ function createStaticHandler(routes, opts) {
|
|
|
691
705
|
loaderHeaders: {},
|
|
692
706
|
actionHeaders: {}
|
|
693
707
|
};
|
|
694
|
-
return
|
|
708
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
695
709
|
}
|
|
696
|
-
if (
|
|
697
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
698
|
-
)) {
|
|
710
|
+
if (generateMiddlewareResponse) {
|
|
699
711
|
invariant(
|
|
700
712
|
requestContext instanceof unstable_RouterContextProvider,
|
|
701
713
|
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
@@ -707,7 +719,7 @@ function createStaticHandler(routes, opts) {
|
|
|
707
719
|
mapRouteProperties
|
|
708
720
|
);
|
|
709
721
|
let renderedStaticContext;
|
|
710
|
-
let response = await
|
|
722
|
+
let response = await runServerMiddlewarePipeline(
|
|
711
723
|
{
|
|
712
724
|
request,
|
|
713
725
|
matches,
|
|
@@ -716,45 +728,27 @@ function createStaticHandler(routes, opts) {
|
|
|
716
728
|
// this to the proper type knowing it's not an `AppLoadContext`
|
|
717
729
|
context: requestContext
|
|
718
730
|
},
|
|
719
|
-
true,
|
|
720
731
|
async () => {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
return isResponse(result3) ? result3 : { location, basename, ...result3 };
|
|
732
|
+
let res = await generateMiddlewareResponse(
|
|
733
|
+
async (revalidationRequest) => {
|
|
734
|
+
let result2 = await queryImpl(
|
|
735
|
+
revalidationRequest,
|
|
736
|
+
location,
|
|
737
|
+
matches,
|
|
738
|
+
requestContext,
|
|
739
|
+
dataStrategy || null,
|
|
740
|
+
skipLoaderErrorBubbling === true,
|
|
741
|
+
null,
|
|
742
|
+
filterMatchesToLoad || null,
|
|
743
|
+
skipRevalidation === true
|
|
744
|
+
);
|
|
745
|
+
if (isResponse(result2)) {
|
|
746
|
+
return result2;
|
|
737
747
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
invariant(respond, "Expected respond to be defined");
|
|
742
|
-
let result2 = await queryImpl(
|
|
743
|
-
request,
|
|
744
|
-
location,
|
|
745
|
-
matches,
|
|
746
|
-
requestContext,
|
|
747
|
-
dataStrategy || null,
|
|
748
|
-
skipLoaderErrorBubbling === true,
|
|
749
|
-
null,
|
|
750
|
-
filterMatchesToLoad || null,
|
|
751
|
-
skipRevalidation === true
|
|
748
|
+
renderedStaticContext = { location, basename, ...result2 };
|
|
749
|
+
return renderedStaticContext;
|
|
750
|
+
}
|
|
752
751
|
);
|
|
753
|
-
if (isResponse(result2)) {
|
|
754
|
-
return result2;
|
|
755
|
-
}
|
|
756
|
-
renderedStaticContext = { location, basename, ...result2 };
|
|
757
|
-
let res = await respond(renderedStaticContext);
|
|
758
752
|
return res;
|
|
759
753
|
},
|
|
760
754
|
async (error, routeId) => {
|
|
@@ -771,7 +765,9 @@ function createStaticHandler(routes, opts) {
|
|
|
771
765
|
error,
|
|
772
766
|
skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
|
|
773
767
|
);
|
|
774
|
-
return
|
|
768
|
+
return generateMiddlewareResponse(
|
|
769
|
+
() => Promise.resolve(staticContext)
|
|
770
|
+
);
|
|
775
771
|
} else {
|
|
776
772
|
let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
|
|
777
773
|
matches,
|
|
@@ -792,7 +788,9 @@ function createStaticHandler(routes, opts) {
|
|
|
792
788
|
actionHeaders: {},
|
|
793
789
|
loaderHeaders: {}
|
|
794
790
|
};
|
|
795
|
-
return
|
|
791
|
+
return generateMiddlewareResponse(
|
|
792
|
+
() => Promise.resolve(staticContext)
|
|
793
|
+
);
|
|
796
794
|
}
|
|
797
795
|
}
|
|
798
796
|
);
|
|
@@ -825,7 +823,7 @@ function createStaticHandler(routes, opts) {
|
|
|
825
823
|
routeId,
|
|
826
824
|
requestContext,
|
|
827
825
|
dataStrategy,
|
|
828
|
-
|
|
826
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
829
827
|
} = {}) {
|
|
830
828
|
let url = new URL(request.url);
|
|
831
829
|
let method = request.method;
|
|
@@ -846,15 +844,13 @@ function createStaticHandler(routes, opts) {
|
|
|
846
844
|
} else if (!match) {
|
|
847
845
|
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
848
846
|
}
|
|
849
|
-
if (
|
|
850
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
851
|
-
)) {
|
|
847
|
+
if (generateMiddlewareResponse) {
|
|
852
848
|
invariant(
|
|
853
849
|
requestContext instanceof unstable_RouterContextProvider,
|
|
854
850
|
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
855
851
|
);
|
|
856
852
|
await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties);
|
|
857
|
-
let response = await
|
|
853
|
+
let response = await runServerMiddlewarePipeline(
|
|
858
854
|
{
|
|
859
855
|
request,
|
|
860
856
|
matches,
|
|
@@ -863,37 +859,31 @@ function createStaticHandler(routes, opts) {
|
|
|
863
859
|
// this to the proper type knowing it's not an `AppLoadContext`
|
|
864
860
|
context: requestContext
|
|
865
861
|
},
|
|
866
|
-
true,
|
|
867
862
|
async () => {
|
|
868
|
-
let
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
863
|
+
let res = await generateMiddlewareResponse(
|
|
864
|
+
async (innerRequest) => {
|
|
865
|
+
let result2 = await queryImpl(
|
|
866
|
+
innerRequest,
|
|
867
|
+
location,
|
|
868
|
+
matches,
|
|
869
|
+
requestContext,
|
|
870
|
+
dataStrategy || null,
|
|
871
|
+
false,
|
|
872
|
+
match,
|
|
873
|
+
null,
|
|
874
|
+
false
|
|
875
|
+
);
|
|
876
|
+
let processed = handleQueryResult(result2);
|
|
877
|
+
return isResponse(processed) ? processed : typeof processed === "string" ? new Response(processed) : Response.json(processed);
|
|
878
|
+
}
|
|
878
879
|
);
|
|
879
|
-
|
|
880
|
-
return respond(result2);
|
|
881
|
-
}
|
|
882
|
-
let error2 = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
883
|
-
if (error2 !== void 0) {
|
|
884
|
-
throw error2;
|
|
885
|
-
}
|
|
886
|
-
let value = result2.actionData ? Object.values(result2.actionData)[0] : Object.values(result2.loaderData)[0];
|
|
887
|
-
return typeof value === "string" ? new Response(value) : Response.json(value);
|
|
880
|
+
return res;
|
|
888
881
|
},
|
|
889
|
-
(
|
|
890
|
-
if (isResponse(
|
|
891
|
-
return
|
|
882
|
+
(error) => {
|
|
883
|
+
if (isResponse(error)) {
|
|
884
|
+
return Promise.resolve(error);
|
|
892
885
|
}
|
|
893
|
-
|
|
894
|
-
status: 500,
|
|
895
|
-
statusText: "Unexpected Server Error"
|
|
896
|
-
});
|
|
886
|
+
throw error;
|
|
897
887
|
}
|
|
898
888
|
);
|
|
899
889
|
return response;
|
|
@@ -909,20 +899,23 @@ function createStaticHandler(routes, opts) {
|
|
|
909
899
|
null,
|
|
910
900
|
false
|
|
911
901
|
);
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
902
|
+
return handleQueryResult(result);
|
|
903
|
+
function handleQueryResult(result2) {
|
|
904
|
+
if (isResponse(result2)) {
|
|
905
|
+
return result2;
|
|
906
|
+
}
|
|
907
|
+
let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
908
|
+
if (error !== void 0) {
|
|
909
|
+
throw error;
|
|
910
|
+
}
|
|
911
|
+
if (result2.actionData) {
|
|
912
|
+
return Object.values(result2.actionData)[0];
|
|
913
|
+
}
|
|
914
|
+
if (result2.loaderData) {
|
|
915
|
+
return Object.values(result2.loaderData)[0];
|
|
916
|
+
}
|
|
917
|
+
return void 0;
|
|
924
918
|
}
|
|
925
|
-
return void 0;
|
|
926
919
|
}
|
|
927
920
|
async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
|
|
928
921
|
invariant(
|
|
@@ -1469,37 +1462,29 @@ async function defaultDataStrategy(args) {
|
|
|
1469
1462
|
});
|
|
1470
1463
|
return keyedResults;
|
|
1471
1464
|
}
|
|
1472
|
-
async function
|
|
1465
|
+
async function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
|
1473
1466
|
let { matches, request, params, context } = args;
|
|
1474
|
-
let
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
);
|
|
1488
|
-
return propagateResult ? result : middlewareState.handlerResult;
|
|
1489
|
-
} catch (e) {
|
|
1490
|
-
if (!middlewareState.middlewareError) {
|
|
1491
|
-
throw e;
|
|
1492
|
-
}
|
|
1493
|
-
let result = await errorHandler(
|
|
1494
|
-
middlewareState.middlewareError.error,
|
|
1495
|
-
middlewareState.middlewareError.routeId
|
|
1467
|
+
let tuples = matches.flatMap(
|
|
1468
|
+
(m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
|
|
1469
|
+
);
|
|
1470
|
+
let result = await callServerRouteMiddleware(
|
|
1471
|
+
{ request, params, context },
|
|
1472
|
+
tuples,
|
|
1473
|
+
handler,
|
|
1474
|
+
errorHandler
|
|
1475
|
+
);
|
|
1476
|
+
if (isDataWithResponseInit(result)) {
|
|
1477
|
+
return new Response(
|
|
1478
|
+
typeof result.data === "string" ? result.data : JSON.stringify(result.data),
|
|
1479
|
+
{ ...result.init }
|
|
1496
1480
|
);
|
|
1497
|
-
{
|
|
1498
|
-
return result;
|
|
1499
|
-
}
|
|
1500
1481
|
}
|
|
1482
|
+
if (isResponse(result)) {
|
|
1483
|
+
return result;
|
|
1484
|
+
}
|
|
1485
|
+
invariant(false, `Expected a Response to be returned from route middleware`);
|
|
1501
1486
|
}
|
|
1502
|
-
async function
|
|
1487
|
+
async function callServerRouteMiddleware(args, middlewares, handler, errorHandler, idx = 0) {
|
|
1503
1488
|
let { request } = args;
|
|
1504
1489
|
if (request.signal.aborted) {
|
|
1505
1490
|
if (request.signal.reason) {
|
|
@@ -1511,8 +1496,8 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1511
1496
|
}
|
|
1512
1497
|
let tuple = middlewares[idx];
|
|
1513
1498
|
if (!tuple) {
|
|
1514
|
-
|
|
1515
|
-
return
|
|
1499
|
+
let result = await handler();
|
|
1500
|
+
return result;
|
|
1516
1501
|
}
|
|
1517
1502
|
let [routeId, middleware] = tuple;
|
|
1518
1503
|
let nextCalled = false;
|
|
@@ -1522,17 +1507,19 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1522
1507
|
throw new Error("You may only call `next()` once per middleware");
|
|
1523
1508
|
}
|
|
1524
1509
|
nextCalled = true;
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
{
|
|
1510
|
+
try {
|
|
1511
|
+
let result = await callServerRouteMiddleware(
|
|
1512
|
+
args,
|
|
1513
|
+
middlewares,
|
|
1514
|
+
handler,
|
|
1515
|
+
errorHandler,
|
|
1516
|
+
idx + 1
|
|
1517
|
+
);
|
|
1534
1518
|
nextResult = result;
|
|
1535
1519
|
return nextResult;
|
|
1520
|
+
} catch (e) {
|
|
1521
|
+
nextResult = await errorHandler(e, routeId);
|
|
1522
|
+
return nextResult;
|
|
1536
1523
|
}
|
|
1537
1524
|
};
|
|
1538
1525
|
try {
|
|
@@ -1545,21 +1532,16 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1545
1532
|
next
|
|
1546
1533
|
);
|
|
1547
1534
|
if (nextCalled) {
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
return result;
|
|
1552
|
-
}
|
|
1535
|
+
return typeof result === "undefined" ? nextResult : result;
|
|
1536
|
+
} else if (isResponse(result) || isDataWithResponseInit(result)) {
|
|
1537
|
+
return result;
|
|
1553
1538
|
} else {
|
|
1554
|
-
|
|
1539
|
+
nextResult = await next();
|
|
1540
|
+
return nextResult;
|
|
1555
1541
|
}
|
|
1556
1542
|
} catch (error) {
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
} else if (middlewareState.middlewareError.error !== error) {
|
|
1560
|
-
middlewareState.middlewareError = { routeId, error };
|
|
1561
|
-
}
|
|
1562
|
-
throw error;
|
|
1543
|
+
let response = await errorHandler(error, routeId);
|
|
1544
|
+
return response;
|
|
1563
1545
|
}
|
|
1564
1546
|
}
|
|
1565
1547
|
function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip) {
|
|
@@ -2334,7 +2316,6 @@ async function processServerAction(request, basename, decodeReply, loadServerAct
|
|
|
2334
2316
|
}
|
|
2335
2317
|
}
|
|
2336
2318
|
async function generateResourceResponse(request, routes, basename, routeId, requestContext, onError) {
|
|
2337
|
-
let result;
|
|
2338
2319
|
try {
|
|
2339
2320
|
const staticHandler = createStaticHandler(routes, {
|
|
2340
2321
|
basename
|
|
@@ -2342,41 +2323,45 @@ async function generateResourceResponse(request, routes, basename, routeId, requ
|
|
|
2342
2323
|
let response = await staticHandler.queryRoute(request, {
|
|
2343
2324
|
routeId,
|
|
2344
2325
|
requestContext,
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
} else {
|
|
2353
|
-
result = Response.json(response);
|
|
2326
|
+
async unstable_generateMiddlewareResponse(queryRoute) {
|
|
2327
|
+
try {
|
|
2328
|
+
let response2 = await queryRoute(request);
|
|
2329
|
+
return generateResourceResponse2(response2);
|
|
2330
|
+
} catch (error) {
|
|
2331
|
+
return generateErrorResponse(error);
|
|
2332
|
+
}
|
|
2354
2333
|
}
|
|
2355
|
-
}
|
|
2334
|
+
});
|
|
2335
|
+
return response;
|
|
2356
2336
|
} catch (error) {
|
|
2337
|
+
return generateErrorResponse(error);
|
|
2338
|
+
}
|
|
2339
|
+
function generateErrorResponse(error) {
|
|
2340
|
+
let response;
|
|
2357
2341
|
if (isResponse(error)) {
|
|
2358
|
-
|
|
2342
|
+
response = error;
|
|
2359
2343
|
} else if (isRouteErrorResponse(error)) {
|
|
2360
2344
|
onError?.(error);
|
|
2361
2345
|
const errorMessage = typeof error.data === "string" ? error.data : error.statusText;
|
|
2362
|
-
|
|
2346
|
+
response = new Response(errorMessage, {
|
|
2363
2347
|
status: error.status,
|
|
2364
2348
|
statusText: error.statusText
|
|
2365
2349
|
});
|
|
2366
2350
|
} else {
|
|
2367
2351
|
onError?.(error);
|
|
2368
|
-
|
|
2369
|
-
status: 500
|
|
2370
|
-
});
|
|
2352
|
+
response = new Response("Internal Server Error", { status: 500 });
|
|
2371
2353
|
}
|
|
2354
|
+
return generateResourceResponse2(response);
|
|
2355
|
+
}
|
|
2356
|
+
function generateResourceResponse2(response) {
|
|
2357
|
+
const headers = new Headers(response.headers);
|
|
2358
|
+
headers.set("React-Router-Resource", "true");
|
|
2359
|
+
return new Response(response.body, {
|
|
2360
|
+
status: response.status,
|
|
2361
|
+
statusText: response.statusText,
|
|
2362
|
+
headers
|
|
2363
|
+
});
|
|
2372
2364
|
}
|
|
2373
|
-
const headers = new Headers(result.headers);
|
|
2374
|
-
headers.set("React-Router-Resource", "true");
|
|
2375
|
-
return new Response(result.body, {
|
|
2376
|
-
status: result.status,
|
|
2377
|
-
statusText: result.statusText,
|
|
2378
|
-
headers
|
|
2379
|
-
});
|
|
2380
2365
|
}
|
|
2381
2366
|
async function generateRenderResponse(request, routes, basename, isDataRequest, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, generateResponse, temporaryReferences) {
|
|
2382
2367
|
let statusCode = 200;
|
|
@@ -2398,7 +2383,7 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
|
|
|
2398
2383
|
skipLoaderErrorBubbling: isDataRequest,
|
|
2399
2384
|
skipRevalidation: isSubmission,
|
|
2400
2385
|
...routeIdsToLoad ? { filterMatchesToLoad: (m) => routeIdsToLoad.includes(m.route.id) } : null,
|
|
2401
|
-
async
|
|
2386
|
+
async unstable_generateMiddlewareResponse(query) {
|
|
2402
2387
|
let formState;
|
|
2403
2388
|
if (request.method === "POST") {
|
|
2404
2389
|
let result2 = await processServerAction(
|
|
@@ -2583,13 +2568,15 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
|
|
|
2583
2568
|
});
|
|
2584
2569
|
let matchesPromise = Promise.all(
|
|
2585
2570
|
staticContext.matches.map((match, i) => {
|
|
2586
|
-
let
|
|
2587
|
-
|
|
2571
|
+
let isBelowErrorBoundary = i > deepestRenderedRouteIdx;
|
|
2572
|
+
let parentId = parentIds[match.route.id];
|
|
2573
|
+
return getRSCRouteMatch({
|
|
2588
2574
|
staticContext,
|
|
2589
2575
|
match,
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2576
|
+
routeIdsToLoad,
|
|
2577
|
+
isBelowErrorBoundary,
|
|
2578
|
+
parentId
|
|
2579
|
+
});
|
|
2593
2580
|
})
|
|
2594
2581
|
);
|
|
2595
2582
|
let patchesPromise = getAdditionalRoutePatches(
|
|
@@ -2605,7 +2592,13 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
|
|
|
2605
2592
|
patches
|
|
2606
2593
|
};
|
|
2607
2594
|
}
|
|
2608
|
-
async function getRSCRouteMatch(
|
|
2595
|
+
async function getRSCRouteMatch({
|
|
2596
|
+
staticContext,
|
|
2597
|
+
match,
|
|
2598
|
+
isBelowErrorBoundary,
|
|
2599
|
+
routeIdsToLoad,
|
|
2600
|
+
parentId
|
|
2601
|
+
}) {
|
|
2609
2602
|
await explodeLazyRoute(match.route);
|
|
2610
2603
|
const Layout = match.route.Layout || React2.Fragment;
|
|
2611
2604
|
const Component = match.route.Component;
|
|
@@ -2615,8 +2608,9 @@ async function getRSCRouteMatch(staticContext, match, shouldRenderComponent, par
|
|
|
2615
2608
|
const actionData = staticContext.actionData?.[match.route.id];
|
|
2616
2609
|
const params = match.params;
|
|
2617
2610
|
let element = void 0;
|
|
2618
|
-
|
|
2619
|
-
|
|
2611
|
+
let shouldLoadRoute = !routeIdsToLoad || routeIdsToLoad.includes(match.route.id);
|
|
2612
|
+
if (Component && shouldLoadRoute) {
|
|
2613
|
+
element = !isBelowErrorBoundary ? React2.createElement(
|
|
2620
2614
|
Layout,
|
|
2621
2615
|
null,
|
|
2622
2616
|
isClientReference(Component) ? React2.createElement(WithComponentProps, {
|