react-router 7.7.1 → 7.8.0-pre.1
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 +87 -5
- package/dist/development/browser-z32v5KVN.d.mts +46 -0
- package/dist/development/{chunk-R73PQUJU.js → chunk-4EVDZJGM.js} +130 -130
- package/dist/{production/chunk-K3SBCRK4.mjs → development/chunk-I22FVTOY.mjs} +177 -134
- package/dist/development/{chunk-K7YFBME3.js → chunk-NGF2R4G7.js} +285 -189
- package/dist/development/{chunk-C37GKA54.mjs → chunk-XFFANEXU.mjs} +266 -170
- package/dist/development/{components-CjQijYga.d.mts → components-CuPfnyiZ.d.mts} +33 -21
- package/dist/{production/route-data-CqEmXQub.d.mts → development/context-DohQKLID.d.mts} +312 -525
- 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/development/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-BzBbJLAD.d.ts} +357 -219
- package/dist/{production/index-react-server-client-KLg-U4nr.d.mts → development/index-react-server-client-CuajY2vy.d.mts} +327 -200
- 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 -71
- package/dist/development/index-react-server.d.ts +291 -71
- package/dist/development/index-react-server.js +209 -182
- package/dist/development/index-react-server.mjs +209 -182
- 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-CpB5xtMm.d.mts +473 -0
- package/dist/{production/routeModules-BR2FO0ix.d.ts → development/routeModules-qBivMBjd.d.ts} +325 -68
- package/dist/production/browser-z32v5KVN.d.mts +46 -0
- package/dist/production/{chunk-4DGLNKXF.js → chunk-4PESVXQ2.js} +130 -130
- package/dist/{development/chunk-KIUJAIYX.mjs → production/chunk-JJOMWYJ4.mjs} +177 -134
- package/dist/production/{chunk-IZ57JD2V.mjs → chunk-P2ZJHOXZ.mjs} +266 -170
- package/dist/production/{chunk-7OQROU2D.js → chunk-RLJ23MYZ.js} +285 -189
- package/dist/production/{components-CjQijYga.d.mts → components-CuPfnyiZ.d.mts} +33 -21
- package/dist/{development/route-data-CqEmXQub.d.mts → production/context-DohQKLID.d.mts} +312 -525
- 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/production/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-BzBbJLAD.d.ts} +357 -219
- package/dist/{development/index-react-server-client-KLg-U4nr.d.mts → production/index-react-server-client-CuajY2vy.d.mts} +327 -200
- 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 -71
- package/dist/production/index-react-server.d.ts +291 -71
- package/dist/production/index-react-server.js +209 -182
- package/dist/production/index-react-server.mjs +209 -182
- 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-CpB5xtMm.d.mts +473 -0
- package/dist/{development/routeModules-BR2FO0ix.d.ts → production/routeModules-qBivMBjd.d.ts} +325 -68
- 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.1
|
|
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,34 @@ 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 (
|
|
912
|
-
return
|
|
903
|
+
(error) => {
|
|
904
|
+
if (isRouteErrorResponse(error)) {
|
|
905
|
+
return Promise.resolve(errorResponseToResponse(error));
|
|
913
906
|
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
907
|
+
if (isResponse(error)) {
|
|
908
|
+
return Promise.resolve(error);
|
|
909
|
+
}
|
|
910
|
+
throw error;
|
|
918
911
|
}
|
|
919
912
|
);
|
|
920
913
|
return response;
|
|
@@ -930,20 +923,23 @@ function createStaticHandler(routes, opts) {
|
|
|
930
923
|
null,
|
|
931
924
|
false
|
|
932
925
|
);
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
926
|
+
return handleQueryResult(result);
|
|
927
|
+
function handleQueryResult(result2) {
|
|
928
|
+
if (isResponse(result2)) {
|
|
929
|
+
return result2;
|
|
930
|
+
}
|
|
931
|
+
let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
932
|
+
if (error !== void 0) {
|
|
933
|
+
throw error;
|
|
934
|
+
}
|
|
935
|
+
if (result2.actionData) {
|
|
936
|
+
return Object.values(result2.actionData)[0];
|
|
937
|
+
}
|
|
938
|
+
if (result2.loaderData) {
|
|
939
|
+
return Object.values(result2.loaderData)[0];
|
|
940
|
+
}
|
|
941
|
+
return void 0;
|
|
945
942
|
}
|
|
946
|
-
return void 0;
|
|
947
943
|
}
|
|
948
944
|
async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
|
|
949
945
|
invariant(
|
|
@@ -1490,37 +1486,23 @@ async function defaultDataStrategy(args) {
|
|
|
1490
1486
|
});
|
|
1491
1487
|
return keyedResults;
|
|
1492
1488
|
}
|
|
1493
|
-
async function
|
|
1489
|
+
async function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
|
1494
1490
|
let { matches, request, params, context } = args;
|
|
1495
|
-
let
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
middlewareState,
|
|
1507
|
-
handler
|
|
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
|
|
1517
|
-
);
|
|
1518
|
-
{
|
|
1519
|
-
return result;
|
|
1520
|
-
}
|
|
1491
|
+
let tuples = matches.flatMap(
|
|
1492
|
+
(m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
|
|
1493
|
+
);
|
|
1494
|
+
let result = await callServerRouteMiddleware(
|
|
1495
|
+
{ request, params, context },
|
|
1496
|
+
tuples,
|
|
1497
|
+
handler,
|
|
1498
|
+
errorHandler
|
|
1499
|
+
);
|
|
1500
|
+
if (isResponse(result)) {
|
|
1501
|
+
return result;
|
|
1521
1502
|
}
|
|
1503
|
+
invariant(false, `Expected a Response to be returned from route middleware`);
|
|
1522
1504
|
}
|
|
1523
|
-
async function
|
|
1505
|
+
async function callServerRouteMiddleware(args, middlewares, handler, errorHandler, idx = 0) {
|
|
1524
1506
|
let { request } = args;
|
|
1525
1507
|
if (request.signal.aborted) {
|
|
1526
1508
|
if (request.signal.reason) {
|
|
@@ -1532,8 +1514,8 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1532
1514
|
}
|
|
1533
1515
|
let tuple = middlewares[idx];
|
|
1534
1516
|
if (!tuple) {
|
|
1535
|
-
|
|
1536
|
-
return
|
|
1517
|
+
let result = await handler();
|
|
1518
|
+
return result;
|
|
1537
1519
|
}
|
|
1538
1520
|
let [routeId, middleware] = tuple;
|
|
1539
1521
|
let nextCalled = false;
|
|
@@ -1543,17 +1525,26 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1543
1525
|
throw new Error("You may only call `next()` once per middleware");
|
|
1544
1526
|
}
|
|
1545
1527
|
nextCalled = true;
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1528
|
+
try {
|
|
1529
|
+
let result = await callServerRouteMiddleware(
|
|
1530
|
+
args,
|
|
1531
|
+
middlewares,
|
|
1532
|
+
handler,
|
|
1533
|
+
errorHandler,
|
|
1534
|
+
idx + 1
|
|
1535
|
+
);
|
|
1536
|
+
if (isDataWithResponseInit(result)) {
|
|
1537
|
+
result = dataWithResponseInitToResponse(result);
|
|
1538
|
+
}
|
|
1555
1539
|
nextResult = result;
|
|
1556
1540
|
return nextResult;
|
|
1541
|
+
} catch (e) {
|
|
1542
|
+
nextResult = await errorHandler(
|
|
1543
|
+
// Convert thrown data() values to ErrorResponses
|
|
1544
|
+
isDataWithResponseInit(e) ? dataWithResponseInitToErrorResponse(e) : e,
|
|
1545
|
+
routeId
|
|
1546
|
+
);
|
|
1547
|
+
return nextResult;
|
|
1557
1548
|
}
|
|
1558
1549
|
};
|
|
1559
1550
|
try {
|
|
@@ -1565,22 +1556,24 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1565
1556
|
},
|
|
1566
1557
|
next
|
|
1567
1558
|
);
|
|
1559
|
+
if (isDataWithResponseInit(result)) {
|
|
1560
|
+
result = dataWithResponseInitToResponse(result);
|
|
1561
|
+
}
|
|
1568
1562
|
if (nextCalled) {
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
return result;
|
|
1573
|
-
}
|
|
1563
|
+
return typeof result === "undefined" ? nextResult : result;
|
|
1564
|
+
} else if (isResponse(result)) {
|
|
1565
|
+
return result;
|
|
1574
1566
|
} else {
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
} catch (error) {
|
|
1578
|
-
if (!middlewareState.middlewareError) {
|
|
1579
|
-
middlewareState.middlewareError = { routeId, error };
|
|
1580
|
-
} else if (middlewareState.middlewareError.error !== error) {
|
|
1581
|
-
middlewareState.middlewareError = { routeId, error };
|
|
1567
|
+
nextResult = await next();
|
|
1568
|
+
return nextResult;
|
|
1582
1569
|
}
|
|
1583
|
-
|
|
1570
|
+
} catch (e) {
|
|
1571
|
+
let response = await errorHandler(
|
|
1572
|
+
// Convert thrown data() values to ErrorResponses
|
|
1573
|
+
isDataWithResponseInit(e) ? dataWithResponseInitToErrorResponse(e) : e,
|
|
1574
|
+
routeId
|
|
1575
|
+
);
|
|
1576
|
+
return response;
|
|
1584
1577
|
}
|
|
1585
1578
|
}
|
|
1586
1579
|
function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip) {
|
|
@@ -2018,6 +2011,28 @@ function getInternalRouterError(status, {
|
|
|
2018
2011
|
true
|
|
2019
2012
|
);
|
|
2020
2013
|
}
|
|
2014
|
+
function dataWithResponseInitToResponse(data2) {
|
|
2015
|
+
return new Response(
|
|
2016
|
+
typeof data2.data === "string" ? data2.data : JSON.stringify(data2.data),
|
|
2017
|
+
data2.init || void 0
|
|
2018
|
+
);
|
|
2019
|
+
}
|
|
2020
|
+
function dataWithResponseInitToErrorResponse(data2) {
|
|
2021
|
+
return new ErrorResponseImpl(
|
|
2022
|
+
data2.init?.status ?? 500,
|
|
2023
|
+
data2.init?.statusText ?? "Internal Server Error",
|
|
2024
|
+
data2.data
|
|
2025
|
+
);
|
|
2026
|
+
}
|
|
2027
|
+
function errorResponseToResponse(error) {
|
|
2028
|
+
return new Response(
|
|
2029
|
+
typeof error.data === "string" ? error.data : JSON.stringify(error.data),
|
|
2030
|
+
{
|
|
2031
|
+
status: error.status,
|
|
2032
|
+
statusText: error.statusText
|
|
2033
|
+
}
|
|
2034
|
+
);
|
|
2035
|
+
}
|
|
2021
2036
|
function isDataStrategyResult(result) {
|
|
2022
2037
|
return result != null && typeof result === "object" && "type" in result && "result" in result && (result.type === "data" /* data */ || result.type === "error" /* error */);
|
|
2023
2038
|
}
|
|
@@ -2355,7 +2370,6 @@ async function processServerAction(request, basename, decodeReply, loadServerAct
|
|
|
2355
2370
|
}
|
|
2356
2371
|
}
|
|
2357
2372
|
async function generateResourceResponse(request, routes, basename, routeId, requestContext, onError) {
|
|
2358
|
-
let result;
|
|
2359
2373
|
try {
|
|
2360
2374
|
const staticHandler = createStaticHandler(routes, {
|
|
2361
2375
|
basename
|
|
@@ -2363,41 +2377,45 @@ async function generateResourceResponse(request, routes, basename, routeId, requ
|
|
|
2363
2377
|
let response = await staticHandler.queryRoute(request, {
|
|
2364
2378
|
routeId,
|
|
2365
2379
|
requestContext,
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
} else {
|
|
2374
|
-
result = Response.json(response);
|
|
2380
|
+
async unstable_generateMiddlewareResponse(queryRoute) {
|
|
2381
|
+
try {
|
|
2382
|
+
let response2 = await queryRoute(request);
|
|
2383
|
+
return generateResourceResponse2(response2);
|
|
2384
|
+
} catch (error) {
|
|
2385
|
+
return generateErrorResponse(error);
|
|
2386
|
+
}
|
|
2375
2387
|
}
|
|
2376
|
-
}
|
|
2388
|
+
});
|
|
2389
|
+
return response;
|
|
2377
2390
|
} catch (error) {
|
|
2391
|
+
return generateErrorResponse(error);
|
|
2392
|
+
}
|
|
2393
|
+
function generateErrorResponse(error) {
|
|
2394
|
+
let response;
|
|
2378
2395
|
if (isResponse(error)) {
|
|
2379
|
-
|
|
2396
|
+
response = error;
|
|
2380
2397
|
} else if (isRouteErrorResponse(error)) {
|
|
2381
2398
|
onError?.(error);
|
|
2382
2399
|
const errorMessage = typeof error.data === "string" ? error.data : error.statusText;
|
|
2383
|
-
|
|
2400
|
+
response = new Response(errorMessage, {
|
|
2384
2401
|
status: error.status,
|
|
2385
2402
|
statusText: error.statusText
|
|
2386
2403
|
});
|
|
2387
2404
|
} else {
|
|
2388
2405
|
onError?.(error);
|
|
2389
|
-
|
|
2390
|
-
status: 500
|
|
2391
|
-
});
|
|
2406
|
+
response = new Response("Internal Server Error", { status: 500 });
|
|
2392
2407
|
}
|
|
2408
|
+
return generateResourceResponse2(response);
|
|
2409
|
+
}
|
|
2410
|
+
function generateResourceResponse2(response) {
|
|
2411
|
+
const headers = new Headers(response.headers);
|
|
2412
|
+
headers.set("React-Router-Resource", "true");
|
|
2413
|
+
return new Response(response.body, {
|
|
2414
|
+
status: response.status,
|
|
2415
|
+
statusText: response.statusText,
|
|
2416
|
+
headers
|
|
2417
|
+
});
|
|
2393
2418
|
}
|
|
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
2419
|
}
|
|
2402
2420
|
async function generateRenderResponse(request, routes, basename, isDataRequest, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, generateResponse, temporaryReferences) {
|
|
2403
2421
|
let statusCode = 200;
|
|
@@ -2419,7 +2437,7 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
|
|
|
2419
2437
|
skipLoaderErrorBubbling: isDataRequest,
|
|
2420
2438
|
skipRevalidation: isSubmission,
|
|
2421
2439
|
...routeIdsToLoad ? { filterMatchesToLoad: (m) => routeIdsToLoad.includes(m.route.id) } : null,
|
|
2422
|
-
async
|
|
2440
|
+
async unstable_generateMiddlewareResponse(query) {
|
|
2423
2441
|
let formState;
|
|
2424
2442
|
if (request.method === "POST") {
|
|
2425
2443
|
let result2 = await processServerAction(
|
|
@@ -2604,13 +2622,15 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
|
|
|
2604
2622
|
});
|
|
2605
2623
|
let matchesPromise = Promise.all(
|
|
2606
2624
|
staticContext.matches.map((match, i) => {
|
|
2607
|
-
let
|
|
2608
|
-
|
|
2625
|
+
let isBelowErrorBoundary = i > deepestRenderedRouteIdx;
|
|
2626
|
+
let parentId = parentIds[match.route.id];
|
|
2627
|
+
return getRSCRouteMatch({
|
|
2609
2628
|
staticContext,
|
|
2610
2629
|
match,
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2630
|
+
routeIdsToLoad,
|
|
2631
|
+
isBelowErrorBoundary,
|
|
2632
|
+
parentId
|
|
2633
|
+
});
|
|
2614
2634
|
})
|
|
2615
2635
|
);
|
|
2616
2636
|
let patchesPromise = getAdditionalRoutePatches(
|
|
@@ -2626,7 +2646,13 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
|
|
|
2626
2646
|
patches
|
|
2627
2647
|
};
|
|
2628
2648
|
}
|
|
2629
|
-
async function getRSCRouteMatch(
|
|
2649
|
+
async function getRSCRouteMatch({
|
|
2650
|
+
staticContext,
|
|
2651
|
+
match,
|
|
2652
|
+
isBelowErrorBoundary,
|
|
2653
|
+
routeIdsToLoad,
|
|
2654
|
+
parentId
|
|
2655
|
+
}) {
|
|
2630
2656
|
await explodeLazyRoute(match.route);
|
|
2631
2657
|
const Layout = match.route.Layout || React2__namespace.Fragment;
|
|
2632
2658
|
const Component = match.route.Component;
|
|
@@ -2636,8 +2662,9 @@ async function getRSCRouteMatch(staticContext, match, shouldRenderComponent, par
|
|
|
2636
2662
|
const actionData = staticContext.actionData?.[match.route.id];
|
|
2637
2663
|
const params = match.params;
|
|
2638
2664
|
let element = void 0;
|
|
2639
|
-
|
|
2640
|
-
|
|
2665
|
+
let shouldLoadRoute = !routeIdsToLoad || routeIdsToLoad.includes(match.route.id);
|
|
2666
|
+
if (Component && shouldLoadRoute) {
|
|
2667
|
+
element = !isBelowErrorBoundary ? React2__namespace.createElement(
|
|
2641
2668
|
Layout,
|
|
2642
2669
|
null,
|
|
2643
2670
|
isClientReference(Component) ? React2__namespace.createElement(WithComponentProps, {
|