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
|
@@ -27,7 +27,7 @@ function _interopNamespace(e) {
|
|
|
27
27
|
var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* react-router v7.
|
|
30
|
+
* react-router v7.8.0-pre.0
|
|
31
31
|
*
|
|
32
32
|
* Copyright (c) Remix Software Inc.
|
|
33
33
|
*
|
|
@@ -113,6 +113,10 @@ function unstable_createContext(defaultValue) {
|
|
|
113
113
|
}
|
|
114
114
|
var _map;
|
|
115
115
|
var unstable_RouterContextProvider = class {
|
|
116
|
+
/**
|
|
117
|
+
* Create a new `unstable_RouterContextProvider` instance
|
|
118
|
+
* @param init An optional initial context map to populate the provider with
|
|
119
|
+
*/
|
|
116
120
|
constructor(init) {
|
|
117
121
|
__privateAdd(this, _map, /* @__PURE__ */ new Map());
|
|
118
122
|
if (init) {
|
|
@@ -121,6 +125,14 @@ var unstable_RouterContextProvider = class {
|
|
|
121
125
|
}
|
|
122
126
|
}
|
|
123
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Access a value from the context. If no value has been set for the context,
|
|
130
|
+
* it will return the context's `defaultValue` if provided, or throw an error
|
|
131
|
+
* if no `defaultValue` was set.
|
|
132
|
+
* @param context The context to get the value for
|
|
133
|
+
* @returns The value for the context, or the context's `defaultValue` if no
|
|
134
|
+
* value was set
|
|
135
|
+
*/
|
|
124
136
|
get(context) {
|
|
125
137
|
if (__privateGet(this, _map).has(context)) {
|
|
126
138
|
return __privateGet(this, _map).get(context);
|
|
@@ -130,6 +142,14 @@ var unstable_RouterContextProvider = class {
|
|
|
130
142
|
}
|
|
131
143
|
throw new Error("No value found for context");
|
|
132
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Set a value for the context. If the context already has a value set, this
|
|
147
|
+
* will overwrite it.
|
|
148
|
+
*
|
|
149
|
+
* @param context The context to set the value for
|
|
150
|
+
* @param value The value to set for the context
|
|
151
|
+
* @returns {void}
|
|
152
|
+
*/
|
|
133
153
|
set(context, value) {
|
|
134
154
|
__privateGet(this, _map).set(context, value);
|
|
135
155
|
}
|
|
@@ -235,6 +255,7 @@ function convertRouteMatchToUiMatch(match, loaderData) {
|
|
|
235
255
|
pathname,
|
|
236
256
|
params,
|
|
237
257
|
data: loaderData[route.id],
|
|
258
|
+
loaderData: loaderData[route.id],
|
|
238
259
|
handle: route.handle
|
|
239
260
|
};
|
|
240
261
|
}
|
|
@@ -665,20 +686,13 @@ function createStaticHandler(routes, opts) {
|
|
|
665
686
|
skipLoaderErrorBubbling,
|
|
666
687
|
skipRevalidation,
|
|
667
688
|
dataStrategy,
|
|
668
|
-
|
|
669
|
-
unstable_respond: respond
|
|
689
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
670
690
|
} = {}) {
|
|
671
691
|
let url = new URL(request.url);
|
|
672
692
|
let method = request.method;
|
|
673
693
|
let location = createLocation("", createPath(url), null, "default");
|
|
674
694
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
675
695
|
requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
|
|
676
|
-
let respondOrStreamStaticContext = (ctx) => {
|
|
677
|
-
return stream ? stream(
|
|
678
|
-
requestContext,
|
|
679
|
-
() => Promise.resolve(ctx)
|
|
680
|
-
) : respond ? respond(ctx) : ctx;
|
|
681
|
-
};
|
|
682
696
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
683
697
|
let error = getInternalRouterError(405, { method });
|
|
684
698
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -695,7 +709,7 @@ function createStaticHandler(routes, opts) {
|
|
|
695
709
|
loaderHeaders: {},
|
|
696
710
|
actionHeaders: {}
|
|
697
711
|
};
|
|
698
|
-
return
|
|
712
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
699
713
|
} else if (!matches) {
|
|
700
714
|
let error = getInternalRouterError(404, { pathname: location.pathname });
|
|
701
715
|
let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
@@ -712,11 +726,9 @@ function createStaticHandler(routes, opts) {
|
|
|
712
726
|
loaderHeaders: {},
|
|
713
727
|
actionHeaders: {}
|
|
714
728
|
};
|
|
715
|
-
return
|
|
729
|
+
return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
|
716
730
|
}
|
|
717
|
-
if (
|
|
718
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
719
|
-
)) {
|
|
731
|
+
if (generateMiddlewareResponse) {
|
|
720
732
|
invariant(
|
|
721
733
|
requestContext instanceof unstable_RouterContextProvider,
|
|
722
734
|
"When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
@@ -728,7 +740,7 @@ function createStaticHandler(routes, opts) {
|
|
|
728
740
|
mapRouteProperties
|
|
729
741
|
);
|
|
730
742
|
let renderedStaticContext;
|
|
731
|
-
let response = await
|
|
743
|
+
let response = await runServerMiddlewarePipeline(
|
|
732
744
|
{
|
|
733
745
|
request,
|
|
734
746
|
matches,
|
|
@@ -737,45 +749,27 @@ function createStaticHandler(routes, opts) {
|
|
|
737
749
|
// this to the proper type knowing it's not an `AppLoadContext`
|
|
738
750
|
context: requestContext
|
|
739
751
|
},
|
|
740
|
-
true,
|
|
741
752
|
async () => {
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
return isResponse(result3) ? result3 : { location, basename, ...result3 };
|
|
753
|
+
let res = await generateMiddlewareResponse(
|
|
754
|
+
async (revalidationRequest) => {
|
|
755
|
+
let result2 = await queryImpl(
|
|
756
|
+
revalidationRequest,
|
|
757
|
+
location,
|
|
758
|
+
matches,
|
|
759
|
+
requestContext,
|
|
760
|
+
dataStrategy || null,
|
|
761
|
+
skipLoaderErrorBubbling === true,
|
|
762
|
+
null,
|
|
763
|
+
filterMatchesToLoad || null,
|
|
764
|
+
skipRevalidation === true
|
|
765
|
+
);
|
|
766
|
+
if (isResponse(result2)) {
|
|
767
|
+
return result2;
|
|
758
768
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
invariant(respond, "Expected respond to be defined");
|
|
763
|
-
let result2 = await queryImpl(
|
|
764
|
-
request,
|
|
765
|
-
location,
|
|
766
|
-
matches,
|
|
767
|
-
requestContext,
|
|
768
|
-
dataStrategy || null,
|
|
769
|
-
skipLoaderErrorBubbling === true,
|
|
770
|
-
null,
|
|
771
|
-
filterMatchesToLoad || null,
|
|
772
|
-
skipRevalidation === true
|
|
769
|
+
renderedStaticContext = { location, basename, ...result2 };
|
|
770
|
+
return renderedStaticContext;
|
|
771
|
+
}
|
|
773
772
|
);
|
|
774
|
-
if (isResponse(result2)) {
|
|
775
|
-
return result2;
|
|
776
|
-
}
|
|
777
|
-
renderedStaticContext = { location, basename, ...result2 };
|
|
778
|
-
let res = await respond(renderedStaticContext);
|
|
779
773
|
return res;
|
|
780
774
|
},
|
|
781
775
|
async (error, routeId) => {
|
|
@@ -792,7 +786,9 @@ function createStaticHandler(routes, opts) {
|
|
|
792
786
|
error,
|
|
793
787
|
skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
|
|
794
788
|
);
|
|
795
|
-
return
|
|
789
|
+
return generateMiddlewareResponse(
|
|
790
|
+
() => Promise.resolve(staticContext)
|
|
791
|
+
);
|
|
796
792
|
} else {
|
|
797
793
|
let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
|
|
798
794
|
matches,
|
|
@@ -813,7 +809,9 @@ function createStaticHandler(routes, opts) {
|
|
|
813
809
|
actionHeaders: {},
|
|
814
810
|
loaderHeaders: {}
|
|
815
811
|
};
|
|
816
|
-
return
|
|
812
|
+
return generateMiddlewareResponse(
|
|
813
|
+
() => Promise.resolve(staticContext)
|
|
814
|
+
);
|
|
817
815
|
}
|
|
818
816
|
}
|
|
819
817
|
);
|
|
@@ -846,7 +844,7 @@ function createStaticHandler(routes, opts) {
|
|
|
846
844
|
routeId,
|
|
847
845
|
requestContext,
|
|
848
846
|
dataStrategy,
|
|
849
|
-
|
|
847
|
+
unstable_generateMiddlewareResponse: generateMiddlewareResponse
|
|
850
848
|
} = {}) {
|
|
851
849
|
let url = new URL(request.url);
|
|
852
850
|
let method = request.method;
|
|
@@ -867,15 +865,13 @@ function createStaticHandler(routes, opts) {
|
|
|
867
865
|
} else if (!match) {
|
|
868
866
|
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
869
867
|
}
|
|
870
|
-
if (
|
|
871
|
-
(m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
|
|
872
|
-
)) {
|
|
868
|
+
if (generateMiddlewareResponse) {
|
|
873
869
|
invariant(
|
|
874
870
|
requestContext instanceof unstable_RouterContextProvider,
|
|
875
871
|
"When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
|
|
876
872
|
);
|
|
877
873
|
await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties);
|
|
878
|
-
let response = await
|
|
874
|
+
let response = await runServerMiddlewarePipeline(
|
|
879
875
|
{
|
|
880
876
|
request,
|
|
881
877
|
matches,
|
|
@@ -884,37 +880,31 @@ function createStaticHandler(routes, opts) {
|
|
|
884
880
|
// this to the proper type knowing it's not an `AppLoadContext`
|
|
885
881
|
context: requestContext
|
|
886
882
|
},
|
|
887
|
-
true,
|
|
888
883
|
async () => {
|
|
889
|
-
let
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
884
|
+
let res = await generateMiddlewareResponse(
|
|
885
|
+
async (innerRequest) => {
|
|
886
|
+
let result2 = await queryImpl(
|
|
887
|
+
innerRequest,
|
|
888
|
+
location,
|
|
889
|
+
matches,
|
|
890
|
+
requestContext,
|
|
891
|
+
dataStrategy || null,
|
|
892
|
+
false,
|
|
893
|
+
match,
|
|
894
|
+
null,
|
|
895
|
+
false
|
|
896
|
+
);
|
|
897
|
+
let processed = handleQueryResult(result2);
|
|
898
|
+
return isResponse(processed) ? processed : typeof processed === "string" ? new Response(processed) : Response.json(processed);
|
|
899
|
+
}
|
|
899
900
|
);
|
|
900
|
-
|
|
901
|
-
return respond(result2);
|
|
902
|
-
}
|
|
903
|
-
let error2 = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
904
|
-
if (error2 !== void 0) {
|
|
905
|
-
throw error2;
|
|
906
|
-
}
|
|
907
|
-
let value = result2.actionData ? Object.values(result2.actionData)[0] : Object.values(result2.loaderData)[0];
|
|
908
|
-
return typeof value === "string" ? new Response(value) : Response.json(value);
|
|
901
|
+
return res;
|
|
909
902
|
},
|
|
910
|
-
(
|
|
911
|
-
if (isResponse(
|
|
912
|
-
return
|
|
903
|
+
(error) => {
|
|
904
|
+
if (isResponse(error)) {
|
|
905
|
+
return Promise.resolve(error);
|
|
913
906
|
}
|
|
914
|
-
|
|
915
|
-
status: 500,
|
|
916
|
-
statusText: "Unexpected Server Error"
|
|
917
|
-
});
|
|
907
|
+
throw error;
|
|
918
908
|
}
|
|
919
909
|
);
|
|
920
910
|
return response;
|
|
@@ -930,20 +920,23 @@ function createStaticHandler(routes, opts) {
|
|
|
930
920
|
null,
|
|
931
921
|
false
|
|
932
922
|
);
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
923
|
+
return handleQueryResult(result);
|
|
924
|
+
function handleQueryResult(result2) {
|
|
925
|
+
if (isResponse(result2)) {
|
|
926
|
+
return result2;
|
|
927
|
+
}
|
|
928
|
+
let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
929
|
+
if (error !== void 0) {
|
|
930
|
+
throw error;
|
|
931
|
+
}
|
|
932
|
+
if (result2.actionData) {
|
|
933
|
+
return Object.values(result2.actionData)[0];
|
|
934
|
+
}
|
|
935
|
+
if (result2.loaderData) {
|
|
936
|
+
return Object.values(result2.loaderData)[0];
|
|
937
|
+
}
|
|
938
|
+
return void 0;
|
|
945
939
|
}
|
|
946
|
-
return void 0;
|
|
947
940
|
}
|
|
948
941
|
async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
|
|
949
942
|
invariant(
|
|
@@ -1490,37 +1483,29 @@ async function defaultDataStrategy(args) {
|
|
|
1490
1483
|
});
|
|
1491
1484
|
return keyedResults;
|
|
1492
1485
|
}
|
|
1493
|
-
async function
|
|
1486
|
+
async function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
|
1494
1487
|
let { matches, request, params, context } = args;
|
|
1495
|
-
let
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
);
|
|
1509
|
-
return propagateResult ? result : middlewareState.handlerResult;
|
|
1510
|
-
} catch (e) {
|
|
1511
|
-
if (!middlewareState.middlewareError) {
|
|
1512
|
-
throw e;
|
|
1513
|
-
}
|
|
1514
|
-
let result = await errorHandler(
|
|
1515
|
-
middlewareState.middlewareError.error,
|
|
1516
|
-
middlewareState.middlewareError.routeId
|
|
1488
|
+
let tuples = matches.flatMap(
|
|
1489
|
+
(m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
|
|
1490
|
+
);
|
|
1491
|
+
let result = await callServerRouteMiddleware(
|
|
1492
|
+
{ request, params, context },
|
|
1493
|
+
tuples,
|
|
1494
|
+
handler,
|
|
1495
|
+
errorHandler
|
|
1496
|
+
);
|
|
1497
|
+
if (isDataWithResponseInit(result)) {
|
|
1498
|
+
return new Response(
|
|
1499
|
+
typeof result.data === "string" ? result.data : JSON.stringify(result.data),
|
|
1500
|
+
{ ...result.init }
|
|
1517
1501
|
);
|
|
1518
|
-
{
|
|
1519
|
-
return result;
|
|
1520
|
-
}
|
|
1521
1502
|
}
|
|
1503
|
+
if (isResponse(result)) {
|
|
1504
|
+
return result;
|
|
1505
|
+
}
|
|
1506
|
+
invariant(false, `Expected a Response to be returned from route middleware`);
|
|
1522
1507
|
}
|
|
1523
|
-
async function
|
|
1508
|
+
async function callServerRouteMiddleware(args, middlewares, handler, errorHandler, idx = 0) {
|
|
1524
1509
|
let { request } = args;
|
|
1525
1510
|
if (request.signal.aborted) {
|
|
1526
1511
|
if (request.signal.reason) {
|
|
@@ -1532,8 +1517,8 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1532
1517
|
}
|
|
1533
1518
|
let tuple = middlewares[idx];
|
|
1534
1519
|
if (!tuple) {
|
|
1535
|
-
|
|
1536
|
-
return
|
|
1520
|
+
let result = await handler();
|
|
1521
|
+
return result;
|
|
1537
1522
|
}
|
|
1538
1523
|
let [routeId, middleware] = tuple;
|
|
1539
1524
|
let nextCalled = false;
|
|
@@ -1543,17 +1528,19 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1543
1528
|
throw new Error("You may only call `next()` once per middleware");
|
|
1544
1529
|
}
|
|
1545
1530
|
nextCalled = true;
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
{
|
|
1531
|
+
try {
|
|
1532
|
+
let result = await callServerRouteMiddleware(
|
|
1533
|
+
args,
|
|
1534
|
+
middlewares,
|
|
1535
|
+
handler,
|
|
1536
|
+
errorHandler,
|
|
1537
|
+
idx + 1
|
|
1538
|
+
);
|
|
1555
1539
|
nextResult = result;
|
|
1556
1540
|
return nextResult;
|
|
1541
|
+
} catch (e) {
|
|
1542
|
+
nextResult = await errorHandler(e, routeId);
|
|
1543
|
+
return nextResult;
|
|
1557
1544
|
}
|
|
1558
1545
|
};
|
|
1559
1546
|
try {
|
|
@@ -1566,21 +1553,16 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1566
1553
|
next
|
|
1567
1554
|
);
|
|
1568
1555
|
if (nextCalled) {
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
return result;
|
|
1573
|
-
}
|
|
1556
|
+
return typeof result === "undefined" ? nextResult : result;
|
|
1557
|
+
} else if (isResponse(result) || isDataWithResponseInit(result)) {
|
|
1558
|
+
return result;
|
|
1574
1559
|
} else {
|
|
1575
|
-
|
|
1560
|
+
nextResult = await next();
|
|
1561
|
+
return nextResult;
|
|
1576
1562
|
}
|
|
1577
1563
|
} catch (error) {
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
} else if (middlewareState.middlewareError.error !== error) {
|
|
1581
|
-
middlewareState.middlewareError = { routeId, error };
|
|
1582
|
-
}
|
|
1583
|
-
throw error;
|
|
1564
|
+
let response = await errorHandler(error, routeId);
|
|
1565
|
+
return response;
|
|
1584
1566
|
}
|
|
1585
1567
|
}
|
|
1586
1568
|
function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip) {
|
|
@@ -2355,7 +2337,6 @@ async function processServerAction(request, basename, decodeReply, loadServerAct
|
|
|
2355
2337
|
}
|
|
2356
2338
|
}
|
|
2357
2339
|
async function generateResourceResponse(request, routes, basename, routeId, requestContext, onError) {
|
|
2358
|
-
let result;
|
|
2359
2340
|
try {
|
|
2360
2341
|
const staticHandler = createStaticHandler(routes, {
|
|
2361
2342
|
basename
|
|
@@ -2363,41 +2344,45 @@ async function generateResourceResponse(request, routes, basename, routeId, requ
|
|
|
2363
2344
|
let response = await staticHandler.queryRoute(request, {
|
|
2364
2345
|
routeId,
|
|
2365
2346
|
requestContext,
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
} else {
|
|
2374
|
-
result = Response.json(response);
|
|
2347
|
+
async unstable_generateMiddlewareResponse(queryRoute) {
|
|
2348
|
+
try {
|
|
2349
|
+
let response2 = await queryRoute(request);
|
|
2350
|
+
return generateResourceResponse2(response2);
|
|
2351
|
+
} catch (error) {
|
|
2352
|
+
return generateErrorResponse(error);
|
|
2353
|
+
}
|
|
2375
2354
|
}
|
|
2376
|
-
}
|
|
2355
|
+
});
|
|
2356
|
+
return response;
|
|
2377
2357
|
} catch (error) {
|
|
2358
|
+
return generateErrorResponse(error);
|
|
2359
|
+
}
|
|
2360
|
+
function generateErrorResponse(error) {
|
|
2361
|
+
let response;
|
|
2378
2362
|
if (isResponse(error)) {
|
|
2379
|
-
|
|
2363
|
+
response = error;
|
|
2380
2364
|
} else if (isRouteErrorResponse(error)) {
|
|
2381
2365
|
onError?.(error);
|
|
2382
2366
|
const errorMessage = typeof error.data === "string" ? error.data : error.statusText;
|
|
2383
|
-
|
|
2367
|
+
response = new Response(errorMessage, {
|
|
2384
2368
|
status: error.status,
|
|
2385
2369
|
statusText: error.statusText
|
|
2386
2370
|
});
|
|
2387
2371
|
} else {
|
|
2388
2372
|
onError?.(error);
|
|
2389
|
-
|
|
2390
|
-
status: 500
|
|
2391
|
-
});
|
|
2373
|
+
response = new Response("Internal Server Error", { status: 500 });
|
|
2392
2374
|
}
|
|
2375
|
+
return generateResourceResponse2(response);
|
|
2376
|
+
}
|
|
2377
|
+
function generateResourceResponse2(response) {
|
|
2378
|
+
const headers = new Headers(response.headers);
|
|
2379
|
+
headers.set("React-Router-Resource", "true");
|
|
2380
|
+
return new Response(response.body, {
|
|
2381
|
+
status: response.status,
|
|
2382
|
+
statusText: response.statusText,
|
|
2383
|
+
headers
|
|
2384
|
+
});
|
|
2393
2385
|
}
|
|
2394
|
-
const headers = new Headers(result.headers);
|
|
2395
|
-
headers.set("React-Router-Resource", "true");
|
|
2396
|
-
return new Response(result.body, {
|
|
2397
|
-
status: result.status,
|
|
2398
|
-
statusText: result.statusText,
|
|
2399
|
-
headers
|
|
2400
|
-
});
|
|
2401
2386
|
}
|
|
2402
2387
|
async function generateRenderResponse(request, routes, basename, isDataRequest, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, generateResponse, temporaryReferences) {
|
|
2403
2388
|
let statusCode = 200;
|
|
@@ -2419,7 +2404,7 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
|
|
|
2419
2404
|
skipLoaderErrorBubbling: isDataRequest,
|
|
2420
2405
|
skipRevalidation: isSubmission,
|
|
2421
2406
|
...routeIdsToLoad ? { filterMatchesToLoad: (m) => routeIdsToLoad.includes(m.route.id) } : null,
|
|
2422
|
-
async
|
|
2407
|
+
async unstable_generateMiddlewareResponse(query) {
|
|
2423
2408
|
let formState;
|
|
2424
2409
|
if (request.method === "POST") {
|
|
2425
2410
|
let result2 = await processServerAction(
|
|
@@ -2604,13 +2589,15 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
|
|
|
2604
2589
|
});
|
|
2605
2590
|
let matchesPromise = Promise.all(
|
|
2606
2591
|
staticContext.matches.map((match, i) => {
|
|
2607
|
-
let
|
|
2608
|
-
|
|
2592
|
+
let isBelowErrorBoundary = i > deepestRenderedRouteIdx;
|
|
2593
|
+
let parentId = parentIds[match.route.id];
|
|
2594
|
+
return getRSCRouteMatch({
|
|
2609
2595
|
staticContext,
|
|
2610
2596
|
match,
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2597
|
+
routeIdsToLoad,
|
|
2598
|
+
isBelowErrorBoundary,
|
|
2599
|
+
parentId
|
|
2600
|
+
});
|
|
2614
2601
|
})
|
|
2615
2602
|
);
|
|
2616
2603
|
let patchesPromise = getAdditionalRoutePatches(
|
|
@@ -2626,7 +2613,13 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
|
|
|
2626
2613
|
patches
|
|
2627
2614
|
};
|
|
2628
2615
|
}
|
|
2629
|
-
async function getRSCRouteMatch(
|
|
2616
|
+
async function getRSCRouteMatch({
|
|
2617
|
+
staticContext,
|
|
2618
|
+
match,
|
|
2619
|
+
isBelowErrorBoundary,
|
|
2620
|
+
routeIdsToLoad,
|
|
2621
|
+
parentId
|
|
2622
|
+
}) {
|
|
2630
2623
|
await explodeLazyRoute(match.route);
|
|
2631
2624
|
const Layout = match.route.Layout || React2__namespace.Fragment;
|
|
2632
2625
|
const Component = match.route.Component;
|
|
@@ -2636,8 +2629,9 @@ async function getRSCRouteMatch(staticContext, match, shouldRenderComponent, par
|
|
|
2636
2629
|
const actionData = staticContext.actionData?.[match.route.id];
|
|
2637
2630
|
const params = match.params;
|
|
2638
2631
|
let element = void 0;
|
|
2639
|
-
|
|
2640
|
-
|
|
2632
|
+
let shouldLoadRoute = !routeIdsToLoad || routeIdsToLoad.includes(match.route.id);
|
|
2633
|
+
if (Component && shouldLoadRoute) {
|
|
2634
|
+
element = !isBelowErrorBoundary ? React2__namespace.createElement(
|
|
2641
2635
|
Layout,
|
|
2642
2636
|
null,
|
|
2643
2637
|
isClientReference(Component) ? React2__namespace.createElement(WithComponentProps, {
|