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
|
@@ -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.1
|
|
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,34 @@ 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 (
|
|
891
|
-
return
|
|
882
|
+
(error) => {
|
|
883
|
+
if (isRouteErrorResponse(error)) {
|
|
884
|
+
return Promise.resolve(errorResponseToResponse(error));
|
|
892
885
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
886
|
+
if (isResponse(error)) {
|
|
887
|
+
return Promise.resolve(error);
|
|
888
|
+
}
|
|
889
|
+
throw error;
|
|
897
890
|
}
|
|
898
891
|
);
|
|
899
892
|
return response;
|
|
@@ -909,20 +902,23 @@ function createStaticHandler(routes, opts) {
|
|
|
909
902
|
null,
|
|
910
903
|
false
|
|
911
904
|
);
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
905
|
+
return handleQueryResult(result);
|
|
906
|
+
function handleQueryResult(result2) {
|
|
907
|
+
if (isResponse(result2)) {
|
|
908
|
+
return result2;
|
|
909
|
+
}
|
|
910
|
+
let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
|
911
|
+
if (error !== void 0) {
|
|
912
|
+
throw error;
|
|
913
|
+
}
|
|
914
|
+
if (result2.actionData) {
|
|
915
|
+
return Object.values(result2.actionData)[0];
|
|
916
|
+
}
|
|
917
|
+
if (result2.loaderData) {
|
|
918
|
+
return Object.values(result2.loaderData)[0];
|
|
919
|
+
}
|
|
920
|
+
return void 0;
|
|
924
921
|
}
|
|
925
|
-
return void 0;
|
|
926
922
|
}
|
|
927
923
|
async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
|
|
928
924
|
invariant(
|
|
@@ -1469,37 +1465,23 @@ async function defaultDataStrategy(args) {
|
|
|
1469
1465
|
});
|
|
1470
1466
|
return keyedResults;
|
|
1471
1467
|
}
|
|
1472
|
-
async function
|
|
1468
|
+
async function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
|
1473
1469
|
let { matches, request, params, context } = args;
|
|
1474
|
-
let
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
middlewareState,
|
|
1486
|
-
handler
|
|
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
|
|
1496
|
-
);
|
|
1497
|
-
{
|
|
1498
|
-
return result;
|
|
1499
|
-
}
|
|
1470
|
+
let tuples = matches.flatMap(
|
|
1471
|
+
(m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
|
|
1472
|
+
);
|
|
1473
|
+
let result = await callServerRouteMiddleware(
|
|
1474
|
+
{ request, params, context },
|
|
1475
|
+
tuples,
|
|
1476
|
+
handler,
|
|
1477
|
+
errorHandler
|
|
1478
|
+
);
|
|
1479
|
+
if (isResponse(result)) {
|
|
1480
|
+
return result;
|
|
1500
1481
|
}
|
|
1482
|
+
invariant(false, `Expected a Response to be returned from route middleware`);
|
|
1501
1483
|
}
|
|
1502
|
-
async function
|
|
1484
|
+
async function callServerRouteMiddleware(args, middlewares, handler, errorHandler, idx = 0) {
|
|
1503
1485
|
let { request } = args;
|
|
1504
1486
|
if (request.signal.aborted) {
|
|
1505
1487
|
if (request.signal.reason) {
|
|
@@ -1511,8 +1493,8 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1511
1493
|
}
|
|
1512
1494
|
let tuple = middlewares[idx];
|
|
1513
1495
|
if (!tuple) {
|
|
1514
|
-
|
|
1515
|
-
return
|
|
1496
|
+
let result = await handler();
|
|
1497
|
+
return result;
|
|
1516
1498
|
}
|
|
1517
1499
|
let [routeId, middleware] = tuple;
|
|
1518
1500
|
let nextCalled = false;
|
|
@@ -1522,17 +1504,26 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1522
1504
|
throw new Error("You may only call `next()` once per middleware");
|
|
1523
1505
|
}
|
|
1524
1506
|
nextCalled = true;
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1507
|
+
try {
|
|
1508
|
+
let result = await callServerRouteMiddleware(
|
|
1509
|
+
args,
|
|
1510
|
+
middlewares,
|
|
1511
|
+
handler,
|
|
1512
|
+
errorHandler,
|
|
1513
|
+
idx + 1
|
|
1514
|
+
);
|
|
1515
|
+
if (isDataWithResponseInit(result)) {
|
|
1516
|
+
result = dataWithResponseInitToResponse(result);
|
|
1517
|
+
}
|
|
1534
1518
|
nextResult = result;
|
|
1535
1519
|
return nextResult;
|
|
1520
|
+
} catch (e) {
|
|
1521
|
+
nextResult = await errorHandler(
|
|
1522
|
+
// Convert thrown data() values to ErrorResponses
|
|
1523
|
+
isDataWithResponseInit(e) ? dataWithResponseInitToErrorResponse(e) : e,
|
|
1524
|
+
routeId
|
|
1525
|
+
);
|
|
1526
|
+
return nextResult;
|
|
1536
1527
|
}
|
|
1537
1528
|
};
|
|
1538
1529
|
try {
|
|
@@ -1544,22 +1535,24 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
|
|
|
1544
1535
|
},
|
|
1545
1536
|
next
|
|
1546
1537
|
);
|
|
1538
|
+
if (isDataWithResponseInit(result)) {
|
|
1539
|
+
result = dataWithResponseInitToResponse(result);
|
|
1540
|
+
}
|
|
1547
1541
|
if (nextCalled) {
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
return result;
|
|
1552
|
-
}
|
|
1542
|
+
return typeof result === "undefined" ? nextResult : result;
|
|
1543
|
+
} else if (isResponse(result)) {
|
|
1544
|
+
return result;
|
|
1553
1545
|
} else {
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
} catch (error) {
|
|
1557
|
-
if (!middlewareState.middlewareError) {
|
|
1558
|
-
middlewareState.middlewareError = { routeId, error };
|
|
1559
|
-
} else if (middlewareState.middlewareError.error !== error) {
|
|
1560
|
-
middlewareState.middlewareError = { routeId, error };
|
|
1546
|
+
nextResult = await next();
|
|
1547
|
+
return nextResult;
|
|
1561
1548
|
}
|
|
1562
|
-
|
|
1549
|
+
} catch (e) {
|
|
1550
|
+
let response = await errorHandler(
|
|
1551
|
+
// Convert thrown data() values to ErrorResponses
|
|
1552
|
+
isDataWithResponseInit(e) ? dataWithResponseInitToErrorResponse(e) : e,
|
|
1553
|
+
routeId
|
|
1554
|
+
);
|
|
1555
|
+
return response;
|
|
1563
1556
|
}
|
|
1564
1557
|
}
|
|
1565
1558
|
function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip) {
|
|
@@ -1997,6 +1990,28 @@ function getInternalRouterError(status, {
|
|
|
1997
1990
|
true
|
|
1998
1991
|
);
|
|
1999
1992
|
}
|
|
1993
|
+
function dataWithResponseInitToResponse(data2) {
|
|
1994
|
+
return new Response(
|
|
1995
|
+
typeof data2.data === "string" ? data2.data : JSON.stringify(data2.data),
|
|
1996
|
+
data2.init || void 0
|
|
1997
|
+
);
|
|
1998
|
+
}
|
|
1999
|
+
function dataWithResponseInitToErrorResponse(data2) {
|
|
2000
|
+
return new ErrorResponseImpl(
|
|
2001
|
+
data2.init?.status ?? 500,
|
|
2002
|
+
data2.init?.statusText ?? "Internal Server Error",
|
|
2003
|
+
data2.data
|
|
2004
|
+
);
|
|
2005
|
+
}
|
|
2006
|
+
function errorResponseToResponse(error) {
|
|
2007
|
+
return new Response(
|
|
2008
|
+
typeof error.data === "string" ? error.data : JSON.stringify(error.data),
|
|
2009
|
+
{
|
|
2010
|
+
status: error.status,
|
|
2011
|
+
statusText: error.statusText
|
|
2012
|
+
}
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
2000
2015
|
function isDataStrategyResult(result) {
|
|
2001
2016
|
return result != null && typeof result === "object" && "type" in result && "result" in result && (result.type === "data" /* data */ || result.type === "error" /* error */);
|
|
2002
2017
|
}
|
|
@@ -2334,7 +2349,6 @@ async function processServerAction(request, basename, decodeReply, loadServerAct
|
|
|
2334
2349
|
}
|
|
2335
2350
|
}
|
|
2336
2351
|
async function generateResourceResponse(request, routes, basename, routeId, requestContext, onError) {
|
|
2337
|
-
let result;
|
|
2338
2352
|
try {
|
|
2339
2353
|
const staticHandler = createStaticHandler(routes, {
|
|
2340
2354
|
basename
|
|
@@ -2342,41 +2356,45 @@ async function generateResourceResponse(request, routes, basename, routeId, requ
|
|
|
2342
2356
|
let response = await staticHandler.queryRoute(request, {
|
|
2343
2357
|
routeId,
|
|
2344
2358
|
requestContext,
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
} else {
|
|
2353
|
-
result = Response.json(response);
|
|
2359
|
+
async unstable_generateMiddlewareResponse(queryRoute) {
|
|
2360
|
+
try {
|
|
2361
|
+
let response2 = await queryRoute(request);
|
|
2362
|
+
return generateResourceResponse2(response2);
|
|
2363
|
+
} catch (error) {
|
|
2364
|
+
return generateErrorResponse(error);
|
|
2365
|
+
}
|
|
2354
2366
|
}
|
|
2355
|
-
}
|
|
2367
|
+
});
|
|
2368
|
+
return response;
|
|
2356
2369
|
} catch (error) {
|
|
2370
|
+
return generateErrorResponse(error);
|
|
2371
|
+
}
|
|
2372
|
+
function generateErrorResponse(error) {
|
|
2373
|
+
let response;
|
|
2357
2374
|
if (isResponse(error)) {
|
|
2358
|
-
|
|
2375
|
+
response = error;
|
|
2359
2376
|
} else if (isRouteErrorResponse(error)) {
|
|
2360
2377
|
onError?.(error);
|
|
2361
2378
|
const errorMessage = typeof error.data === "string" ? error.data : error.statusText;
|
|
2362
|
-
|
|
2379
|
+
response = new Response(errorMessage, {
|
|
2363
2380
|
status: error.status,
|
|
2364
2381
|
statusText: error.statusText
|
|
2365
2382
|
});
|
|
2366
2383
|
} else {
|
|
2367
2384
|
onError?.(error);
|
|
2368
|
-
|
|
2369
|
-
status: 500
|
|
2370
|
-
});
|
|
2385
|
+
response = new Response("Internal Server Error", { status: 500 });
|
|
2371
2386
|
}
|
|
2387
|
+
return generateResourceResponse2(response);
|
|
2388
|
+
}
|
|
2389
|
+
function generateResourceResponse2(response) {
|
|
2390
|
+
const headers = new Headers(response.headers);
|
|
2391
|
+
headers.set("React-Router-Resource", "true");
|
|
2392
|
+
return new Response(response.body, {
|
|
2393
|
+
status: response.status,
|
|
2394
|
+
statusText: response.statusText,
|
|
2395
|
+
headers
|
|
2396
|
+
});
|
|
2372
2397
|
}
|
|
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
2398
|
}
|
|
2381
2399
|
async function generateRenderResponse(request, routes, basename, isDataRequest, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, generateResponse, temporaryReferences) {
|
|
2382
2400
|
let statusCode = 200;
|
|
@@ -2398,7 +2416,7 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
|
|
|
2398
2416
|
skipLoaderErrorBubbling: isDataRequest,
|
|
2399
2417
|
skipRevalidation: isSubmission,
|
|
2400
2418
|
...routeIdsToLoad ? { filterMatchesToLoad: (m) => routeIdsToLoad.includes(m.route.id) } : null,
|
|
2401
|
-
async
|
|
2419
|
+
async unstable_generateMiddlewareResponse(query) {
|
|
2402
2420
|
let formState;
|
|
2403
2421
|
if (request.method === "POST") {
|
|
2404
2422
|
let result2 = await processServerAction(
|
|
@@ -2583,13 +2601,15 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
|
|
|
2583
2601
|
});
|
|
2584
2602
|
let matchesPromise = Promise.all(
|
|
2585
2603
|
staticContext.matches.map((match, i) => {
|
|
2586
|
-
let
|
|
2587
|
-
|
|
2604
|
+
let isBelowErrorBoundary = i > deepestRenderedRouteIdx;
|
|
2605
|
+
let parentId = parentIds[match.route.id];
|
|
2606
|
+
return getRSCRouteMatch({
|
|
2588
2607
|
staticContext,
|
|
2589
2608
|
match,
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2609
|
+
routeIdsToLoad,
|
|
2610
|
+
isBelowErrorBoundary,
|
|
2611
|
+
parentId
|
|
2612
|
+
});
|
|
2593
2613
|
})
|
|
2594
2614
|
);
|
|
2595
2615
|
let patchesPromise = getAdditionalRoutePatches(
|
|
@@ -2605,7 +2625,13 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
|
|
|
2605
2625
|
patches
|
|
2606
2626
|
};
|
|
2607
2627
|
}
|
|
2608
|
-
async function getRSCRouteMatch(
|
|
2628
|
+
async function getRSCRouteMatch({
|
|
2629
|
+
staticContext,
|
|
2630
|
+
match,
|
|
2631
|
+
isBelowErrorBoundary,
|
|
2632
|
+
routeIdsToLoad,
|
|
2633
|
+
parentId
|
|
2634
|
+
}) {
|
|
2609
2635
|
await explodeLazyRoute(match.route);
|
|
2610
2636
|
const Layout = match.route.Layout || React2.Fragment;
|
|
2611
2637
|
const Component = match.route.Component;
|
|
@@ -2615,8 +2641,9 @@ async function getRSCRouteMatch(staticContext, match, shouldRenderComponent, par
|
|
|
2615
2641
|
const actionData = staticContext.actionData?.[match.route.id];
|
|
2616
2642
|
const params = match.params;
|
|
2617
2643
|
let element = void 0;
|
|
2618
|
-
|
|
2619
|
-
|
|
2644
|
+
let shouldLoadRoute = !routeIdsToLoad || routeIdsToLoad.includes(match.route.id);
|
|
2645
|
+
if (Component && shouldLoadRoute) {
|
|
2646
|
+
element = !isBelowErrorBoundary ? React2.createElement(
|
|
2620
2647
|
Layout,
|
|
2621
2648
|
null,
|
|
2622
2649
|
isClientReference(Component) ? React2.createElement(WithComponentProps, {
|