react-router 7.8.0 → 7.8.1-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 +19 -0
- package/dist/development/{chunk-VC6RBZTR.js → chunk-3JDDYHAM.js} +130 -130
- package/dist/development/{chunk-EVX7OBGB.js → chunk-5556IWOV.js} +98 -83
- package/dist/development/{chunk-ZYFC6VSF.mjs → chunk-74543KUN.mjs} +62 -47
- package/dist/{production/chunk-XPGU3ZMH.mjs → development/chunk-NL6TORMN.mjs} +147 -33
- package/dist/development/dom-export.js +3 -3
- package/dist/development/dom-export.mjs +3 -3
- package/dist/{production/index-react-server-client-DXb0OgpJ.d.mts → development/index-react-server-client-11fLy3qB.d.mts} +1 -1
- package/dist/development/{index-react-server-client-CMphySRb.d.ts → index-react-server-client-BQ6FxdA_.d.ts} +1 -1
- package/dist/development/index-react-server-client.d.mts +2 -2
- 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 +38 -1
- package/dist/development/index-react-server.d.ts +38 -1
- package/dist/development/index-react-server.js +56 -45
- package/dist/development/index-react-server.mjs +56 -46
- package/dist/development/index.d.mts +42 -4
- package/dist/development/index.d.ts +42 -4
- package/dist/development/index.js +242 -128
- package/dist/development/index.mjs +3 -3
- package/dist/development/lib/types/internal.d.mts +6 -3
- package/dist/development/lib/types/internal.d.ts +6 -3
- 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 → route-data-CNjObrhZ.d.mts} +1 -1
- package/dist/development/{routeModules-qBivMBjd.d.ts → routeModules-C3oqzPpI.d.ts} +1 -1
- package/dist/production/{chunk-BOD6JCOU.js → chunk-3OSMCWIR.js} +98 -83
- package/dist/production/{chunk-SIHON65V.mjs → chunk-HVGIEXH6.mjs} +62 -47
- package/dist/{development/chunk-HZX6U7MI.mjs → production/chunk-J44BHEXU.mjs} +147 -33
- package/dist/production/{chunk-O6DRQPUD.js → chunk-OE6UW5JS.js} +130 -130
- package/dist/production/dom-export.js +3 -3
- package/dist/production/dom-export.mjs +3 -3
- package/dist/{development/index-react-server-client-DXb0OgpJ.d.mts → production/index-react-server-client-11fLy3qB.d.mts} +1 -1
- package/dist/production/{index-react-server-client-CMphySRb.d.ts → index-react-server-client-BQ6FxdA_.d.ts} +1 -1
- package/dist/production/index-react-server-client.d.mts +2 -2
- 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 +38 -1
- package/dist/production/index-react-server.d.ts +38 -1
- package/dist/production/index-react-server.js +56 -45
- package/dist/production/index-react-server.mjs +56 -46
- package/dist/production/index.d.mts +42 -4
- package/dist/production/index.d.ts +42 -4
- package/dist/production/index.js +242 -128
- package/dist/production/index.mjs +3 -3
- package/dist/production/lib/types/internal.d.mts +6 -3
- package/dist/production/lib/types/internal.d.ts +6 -3
- 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 → route-data-CNjObrhZ.d.mts} +1 -1
- package/dist/production/{routeModules-qBivMBjd.d.ts → routeModules-C3oqzPpI.d.ts} +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v7.8.
|
|
2
|
+
* react-router v7.8.1-pre.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -513,8 +513,8 @@ function convertRouteMatchToUiMatch(match, loaderData) {
|
|
|
513
513
|
handle: route.handle
|
|
514
514
|
};
|
|
515
515
|
}
|
|
516
|
-
function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "") {
|
|
517
|
-
let flattenRoute = (route, index, relativePath) => {
|
|
516
|
+
function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "", _hasParentOptionalSegments = false) {
|
|
517
|
+
let flattenRoute = (route, index, hasParentOptionalSegments = _hasParentOptionalSegments, relativePath) => {
|
|
518
518
|
let meta = {
|
|
519
519
|
relativePath: relativePath === void 0 ? route.path || "" : relativePath,
|
|
520
520
|
caseSensitive: route.caseSensitive === true,
|
|
@@ -522,6 +522,9 @@ function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "")
|
|
|
522
522
|
route
|
|
523
523
|
};
|
|
524
524
|
if (meta.relativePath.startsWith("/")) {
|
|
525
|
+
if (!meta.relativePath.startsWith(parentPath) && hasParentOptionalSegments) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
525
528
|
invariant(
|
|
526
529
|
meta.relativePath.startsWith(parentPath),
|
|
527
530
|
`Absolute route path "${meta.relativePath}" nested under path "${parentPath}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`
|
|
@@ -537,7 +540,13 @@ function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "")
|
|
|
537
540
|
route.index !== true,
|
|
538
541
|
`Index routes must not have child routes. Please remove all child routes from route path "${path}".`
|
|
539
542
|
);
|
|
540
|
-
flattenRoutes(
|
|
543
|
+
flattenRoutes(
|
|
544
|
+
route.children,
|
|
545
|
+
branches,
|
|
546
|
+
routesMeta,
|
|
547
|
+
path,
|
|
548
|
+
hasParentOptionalSegments
|
|
549
|
+
);
|
|
541
550
|
}
|
|
542
551
|
if (route.path == null && !route.index) {
|
|
543
552
|
return;
|
|
@@ -553,7 +562,7 @@ function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "")
|
|
|
553
562
|
flattenRoute(route, index);
|
|
554
563
|
} else {
|
|
555
564
|
for (let exploded of explodeOptionalSegments(route.path)) {
|
|
556
|
-
flattenRoute(route, index, exploded);
|
|
565
|
+
flattenRoute(route, index, true, exploded);
|
|
557
566
|
}
|
|
558
567
|
}
|
|
559
568
|
});
|
|
@@ -745,7 +754,7 @@ function compilePath(path, caseSensitive = false, end = true) {
|
|
|
745
754
|
params.push({ paramName, isOptional: isOptional != null });
|
|
746
755
|
return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
|
|
747
756
|
}
|
|
748
|
-
);
|
|
757
|
+
).replace(/\/([\w-]+)\?(\/|$)/g, "(/$1)?$2");
|
|
749
758
|
if (path.endsWith("*")) {
|
|
750
759
|
params.push({ paramName: "*" });
|
|
751
760
|
regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
|
|
@@ -2814,9 +2823,23 @@ function createStaticHandler(routes, opts) {
|
|
|
2814
2823
|
return res;
|
|
2815
2824
|
},
|
|
2816
2825
|
async (error, routeId) => {
|
|
2817
|
-
if (
|
|
2826
|
+
if (isRedirectResponse(error)) {
|
|
2818
2827
|
return error;
|
|
2819
2828
|
}
|
|
2829
|
+
if (isResponse(error)) {
|
|
2830
|
+
try {
|
|
2831
|
+
error = new ErrorResponseImpl(
|
|
2832
|
+
error.status,
|
|
2833
|
+
error.statusText,
|
|
2834
|
+
await parseResponseBody(error)
|
|
2835
|
+
);
|
|
2836
|
+
} catch (e) {
|
|
2837
|
+
error = e;
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
if (isDataWithResponseInit(error)) {
|
|
2841
|
+
error = dataWithResponseInitToErrorResponse(error);
|
|
2842
|
+
}
|
|
2820
2843
|
if (renderedStaticContext) {
|
|
2821
2844
|
if (routeId in renderedStaticContext.loaderData) {
|
|
2822
2845
|
renderedStaticContext.loaderData[routeId] = void 0;
|
|
@@ -2942,8 +2965,8 @@ function createStaticHandler(routes, opts) {
|
|
|
2942
2965
|
return res;
|
|
2943
2966
|
},
|
|
2944
2967
|
(error) => {
|
|
2945
|
-
if (
|
|
2946
|
-
return Promise.resolve(
|
|
2968
|
+
if (isDataWithResponseInit(error)) {
|
|
2969
|
+
return Promise.resolve(dataWithResponseInitToResponse(error));
|
|
2947
2970
|
}
|
|
2948
2971
|
if (isResponse(error)) {
|
|
2949
2972
|
return Promise.resolve(error);
|
|
@@ -3272,8 +3295,12 @@ function createStaticHandler(routes, opts) {
|
|
|
3272
3295
|
basename
|
|
3273
3296
|
);
|
|
3274
3297
|
}
|
|
3275
|
-
if (
|
|
3276
|
-
|
|
3298
|
+
if (isRouteRequest) {
|
|
3299
|
+
if (isResponse(result.result)) {
|
|
3300
|
+
throw result;
|
|
3301
|
+
} else if (isDataWithResponseInit(result.result)) {
|
|
3302
|
+
throw dataWithResponseInitToResponse(result.result);
|
|
3303
|
+
}
|
|
3277
3304
|
}
|
|
3278
3305
|
dataResults[match.route.id] = await convertDataStrategyResultToDataResult(result);
|
|
3279
3306
|
})
|
|
@@ -3941,9 +3968,15 @@ function clientMiddlewareErrorHandler(error, routeId, matches, didCallHandler) {
|
|
|
3941
3968
|
[routeId]: { type: "error", result: error }
|
|
3942
3969
|
};
|
|
3943
3970
|
} else {
|
|
3971
|
+
let maxBoundaryIdx = Math.min(
|
|
3972
|
+
// Throwing route
|
|
3973
|
+
matches.findIndex((m) => m.route.id === routeId) || 0,
|
|
3974
|
+
// or the shallowest route that needs to load data
|
|
3975
|
+
matches.findIndex((m) => m.unstable_shouldCallHandler()) || 0
|
|
3976
|
+
);
|
|
3944
3977
|
let boundaryRouteId = findNearestBoundary(
|
|
3945
3978
|
matches,
|
|
3946
|
-
matches.
|
|
3979
|
+
matches[maxBoundaryIdx].route.id
|
|
3947
3980
|
).route.id;
|
|
3948
3981
|
return {
|
|
3949
3982
|
[boundaryRouteId]: { type: "error", result: error }
|
|
@@ -4003,11 +4036,7 @@ async function callServerRouteMiddleware(args, middlewares, handler, errorHandle
|
|
|
4003
4036
|
nextResult = result;
|
|
4004
4037
|
return nextResult;
|
|
4005
4038
|
} catch (e) {
|
|
4006
|
-
nextResult = await errorHandler(
|
|
4007
|
-
// Convert thrown data() values to ErrorResponses
|
|
4008
|
-
isDataWithResponseInit(e) ? dataWithResponseInitToErrorResponse(e) : e,
|
|
4009
|
-
routeId
|
|
4010
|
-
);
|
|
4039
|
+
nextResult = await errorHandler(e, routeId);
|
|
4011
4040
|
return nextResult;
|
|
4012
4041
|
}
|
|
4013
4042
|
};
|
|
@@ -4032,11 +4061,7 @@ async function callServerRouteMiddleware(args, middlewares, handler, errorHandle
|
|
|
4032
4061
|
return nextResult;
|
|
4033
4062
|
}
|
|
4034
4063
|
} catch (e) {
|
|
4035
|
-
let response = await errorHandler(
|
|
4036
|
-
// Convert thrown data() values to ErrorResponses
|
|
4037
|
-
isDataWithResponseInit(e) ? dataWithResponseInitToErrorResponse(e) : e,
|
|
4038
|
-
routeId
|
|
4039
|
-
);
|
|
4064
|
+
let response = await errorHandler(e, routeId);
|
|
4040
4065
|
return response;
|
|
4041
4066
|
}
|
|
4042
4067
|
}
|
|
@@ -4362,21 +4387,19 @@ async function callLoaderOrAction({
|
|
|
4362
4387
|
}
|
|
4363
4388
|
return result;
|
|
4364
4389
|
}
|
|
4390
|
+
async function parseResponseBody(response) {
|
|
4391
|
+
let contentType = response.headers.get("Content-Type");
|
|
4392
|
+
if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
|
4393
|
+
return response.body == null ? null : response.json();
|
|
4394
|
+
}
|
|
4395
|
+
return response.text();
|
|
4396
|
+
}
|
|
4365
4397
|
async function convertDataStrategyResultToDataResult(dataStrategyResult) {
|
|
4366
4398
|
let { result, type } = dataStrategyResult;
|
|
4367
4399
|
if (isResponse(result)) {
|
|
4368
4400
|
let data2;
|
|
4369
4401
|
try {
|
|
4370
|
-
|
|
4371
|
-
if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
|
4372
|
-
if (result.body == null) {
|
|
4373
|
-
data2 = null;
|
|
4374
|
-
} else {
|
|
4375
|
-
data2 = await result.json();
|
|
4376
|
-
}
|
|
4377
|
-
} else {
|
|
4378
|
-
data2 = await result.text();
|
|
4379
|
-
}
|
|
4402
|
+
data2 = await parseResponseBody(result);
|
|
4380
4403
|
} catch (e) {
|
|
4381
4404
|
return { type: "error" /* error */, error: e };
|
|
4382
4405
|
}
|
|
@@ -4706,10 +4729,7 @@ function isHashChangeOnly(a, b) {
|
|
|
4706
4729
|
return false;
|
|
4707
4730
|
}
|
|
4708
4731
|
function dataWithResponseInitToResponse(data2) {
|
|
4709
|
-
return
|
|
4710
|
-
typeof data2.data === "string" ? data2.data : JSON.stringify(data2.data),
|
|
4711
|
-
data2.init || void 0
|
|
4712
|
-
);
|
|
4732
|
+
return Response.json(data2.data, data2.init ?? void 0);
|
|
4713
4733
|
}
|
|
4714
4734
|
function dataWithResponseInitToErrorResponse(data2) {
|
|
4715
4735
|
return new ErrorResponseImpl(
|
|
@@ -4718,15 +4738,6 @@ function dataWithResponseInitToErrorResponse(data2) {
|
|
|
4718
4738
|
data2.data
|
|
4719
4739
|
);
|
|
4720
4740
|
}
|
|
4721
|
-
function errorResponseToResponse(error) {
|
|
4722
|
-
return new Response(
|
|
4723
|
-
typeof error.data === "string" ? error.data : JSON.stringify(error.data),
|
|
4724
|
-
{
|
|
4725
|
-
status: error.status,
|
|
4726
|
-
statusText: error.statusText
|
|
4727
|
-
}
|
|
4728
|
-
);
|
|
4729
|
-
}
|
|
4730
4741
|
function isDataStrategyResult(result) {
|
|
4731
4742
|
return result != null && typeof result === "object" && "type" in result && "result" in result && (result.type === "data" /* data */ || result.type === "error" /* error */);
|
|
4732
4743
|
}
|
|
@@ -8698,6 +8709,9 @@ function isValidMetaTag(tagName) {
|
|
|
8698
8709
|
return typeof tagName === "string" && /^(meta|link)$/.test(tagName);
|
|
8699
8710
|
}
|
|
8700
8711
|
var isHydrated = false;
|
|
8712
|
+
function setIsHydrated() {
|
|
8713
|
+
isHydrated = true;
|
|
8714
|
+
}
|
|
8701
8715
|
function Scripts(scriptProps) {
|
|
8702
8716
|
let {
|
|
8703
8717
|
manifest,
|
|
@@ -8716,7 +8730,7 @@ function Scripts(scriptProps) {
|
|
|
8716
8730
|
}
|
|
8717
8731
|
let matches = getActiveMatches(routerMatches, null, isSpaMode);
|
|
8718
8732
|
React8.useEffect(() => {
|
|
8719
|
-
|
|
8733
|
+
setIsHydrated();
|
|
8720
8734
|
}, []);
|
|
8721
8735
|
let initialScripts = React8.useMemo(() => {
|
|
8722
8736
|
if (isRSCRouterContext) {
|
|
@@ -8972,7 +8986,7 @@ var isBrowser = typeof window !== "undefined" && typeof window.document !== "und
|
|
|
8972
8986
|
try {
|
|
8973
8987
|
if (isBrowser) {
|
|
8974
8988
|
window.__reactRouterVersion = // @ts-expect-error
|
|
8975
|
-
"7.8.
|
|
8989
|
+
"7.8.1-pre.1";
|
|
8976
8990
|
}
|
|
8977
8991
|
} catch (e) {
|
|
8978
8992
|
}
|
|
@@ -10171,6 +10185,7 @@ export {
|
|
|
10171
10185
|
Links,
|
|
10172
10186
|
PrefetchPageLinks,
|
|
10173
10187
|
Meta,
|
|
10188
|
+
setIsHydrated,
|
|
10174
10189
|
Scripts,
|
|
10175
10190
|
createBrowserRouter,
|
|
10176
10191
|
createHashRouter,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v7.8.
|
|
2
|
+
* react-router v7.8.1-pre.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -46,6 +46,7 @@ import {
|
|
|
46
46
|
redirect,
|
|
47
47
|
redirectDocument,
|
|
48
48
|
replace,
|
|
49
|
+
setIsHydrated,
|
|
49
50
|
shouldHydrateRouteLoader,
|
|
50
51
|
singleFetchUrl,
|
|
51
52
|
stripBasename,
|
|
@@ -57,7 +58,7 @@ import {
|
|
|
57
58
|
withComponentProps,
|
|
58
59
|
withErrorBoundaryProps,
|
|
59
60
|
withHydrateFallbackProps
|
|
60
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-HVGIEXH6.mjs";
|
|
61
62
|
|
|
62
63
|
// lib/dom/ssr/server.tsx
|
|
63
64
|
import * as React from "react";
|
|
@@ -1122,6 +1123,28 @@ var createRequestHandler = (build, mode) => {
|
|
|
1122
1123
|
let isSpaMode = getBuildTimeHeader(request, "X-React-Router-SPA-Mode") === "yes";
|
|
1123
1124
|
if (!_build.ssr) {
|
|
1124
1125
|
let decodedPath = decodeURI(normalizedPath);
|
|
1126
|
+
if (normalizedBasename !== "/") {
|
|
1127
|
+
let strippedPath = stripBasename(decodedPath, normalizedBasename);
|
|
1128
|
+
if (strippedPath == null) {
|
|
1129
|
+
errorHandler(
|
|
1130
|
+
new ErrorResponseImpl(
|
|
1131
|
+
404,
|
|
1132
|
+
"Not Found",
|
|
1133
|
+
`Refusing to prerender the \`${decodedPath}\` path because it does not start with the basename \`${normalizedBasename}\``
|
|
1134
|
+
),
|
|
1135
|
+
{
|
|
1136
|
+
context: loadContext,
|
|
1137
|
+
params,
|
|
1138
|
+
request
|
|
1139
|
+
}
|
|
1140
|
+
);
|
|
1141
|
+
return new Response("Not Found", {
|
|
1142
|
+
status: 404,
|
|
1143
|
+
statusText: "Not Found"
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
decodedPath = strippedPath;
|
|
1147
|
+
}
|
|
1125
1148
|
if (_build.prerender.length === 0) {
|
|
1126
1149
|
isSpaMode = true;
|
|
1127
1150
|
} else if (!_build.prerender.includes(decodedPath) && !_build.prerender.includes(decodedPath + "/")) {
|
|
@@ -1834,6 +1857,26 @@ function RSCDefaultRootErrorBoundary({
|
|
|
1834
1857
|
);
|
|
1835
1858
|
}
|
|
1836
1859
|
|
|
1860
|
+
// lib/rsc/route-modules.ts
|
|
1861
|
+
function createRSCRouteModules(payload) {
|
|
1862
|
+
const routeModules = {};
|
|
1863
|
+
for (const match of payload.matches) {
|
|
1864
|
+
populateRSCRouteModules(routeModules, match);
|
|
1865
|
+
}
|
|
1866
|
+
return routeModules;
|
|
1867
|
+
}
|
|
1868
|
+
function populateRSCRouteModules(routeModules, matches) {
|
|
1869
|
+
matches = Array.isArray(matches) ? matches : [matches];
|
|
1870
|
+
for (const match of matches) {
|
|
1871
|
+
routeModules[match.id] = {
|
|
1872
|
+
links: match.links,
|
|
1873
|
+
meta: match.meta,
|
|
1874
|
+
default: noopComponent
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
var noopComponent = () => null;
|
|
1879
|
+
|
|
1837
1880
|
// lib/rsc/browser.tsx
|
|
1838
1881
|
function createCallServer({
|
|
1839
1882
|
createFromReadableStream,
|
|
@@ -1867,7 +1910,7 @@ function createCallServer({
|
|
|
1867
1910
|
window.location.href = payload.location;
|
|
1868
1911
|
return;
|
|
1869
1912
|
}
|
|
1870
|
-
globalVar.
|
|
1913
|
+
globalVar.__reactRouterDataRouter.navigate(payload.location, {
|
|
1871
1914
|
replace: payload.replace
|
|
1872
1915
|
});
|
|
1873
1916
|
return payload.actionResult;
|
|
@@ -1888,34 +1931,38 @@ function createCallServer({
|
|
|
1888
1931
|
window.location.href = rerender.location;
|
|
1889
1932
|
return;
|
|
1890
1933
|
}
|
|
1891
|
-
globalVar.
|
|
1934
|
+
globalVar.__reactRouterDataRouter.navigate(rerender.location, {
|
|
1892
1935
|
replace: rerender.replace
|
|
1893
1936
|
});
|
|
1894
1937
|
return;
|
|
1895
1938
|
}
|
|
1896
1939
|
let lastMatch;
|
|
1897
1940
|
for (const match of rerender.matches) {
|
|
1898
|
-
globalVar.
|
|
1941
|
+
globalVar.__reactRouterDataRouter.patchRoutes(
|
|
1899
1942
|
lastMatch?.id ?? null,
|
|
1900
1943
|
[createRouteFromServerManifest(match)],
|
|
1901
1944
|
true
|
|
1902
1945
|
);
|
|
1903
1946
|
lastMatch = match;
|
|
1904
1947
|
}
|
|
1905
|
-
window.
|
|
1948
|
+
window.__reactRouterDataRouter._internalSetStateDoNotUseOrYouWillBreakYourApp(
|
|
1949
|
+
{}
|
|
1950
|
+
);
|
|
1906
1951
|
React4.startTransition(() => {
|
|
1907
|
-
window.
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1952
|
+
window.__reactRouterDataRouter._internalSetStateDoNotUseOrYouWillBreakYourApp(
|
|
1953
|
+
{
|
|
1954
|
+
loaderData: Object.assign(
|
|
1955
|
+
{},
|
|
1956
|
+
globalVar.__reactRouterDataRouter.state.loaderData,
|
|
1957
|
+
rerender.loaderData
|
|
1958
|
+
),
|
|
1959
|
+
errors: rerender.errors ? Object.assign(
|
|
1960
|
+
{},
|
|
1961
|
+
globalVar.__reactRouterDataRouter.state.errors,
|
|
1962
|
+
rerender.errors
|
|
1963
|
+
) : null
|
|
1964
|
+
}
|
|
1965
|
+
);
|
|
1919
1966
|
});
|
|
1920
1967
|
}
|
|
1921
1968
|
}
|
|
@@ -1931,8 +1978,14 @@ function createRouterFromPayload({
|
|
|
1931
1978
|
payload
|
|
1932
1979
|
}) {
|
|
1933
1980
|
const globalVar = window;
|
|
1934
|
-
if (globalVar.
|
|
1981
|
+
if (globalVar.__reactRouterDataRouter && globalVar.__reactRouterRouteModules)
|
|
1982
|
+
return {
|
|
1983
|
+
router: globalVar.__reactRouterDataRouter,
|
|
1984
|
+
routeModules: globalVar.__reactRouterRouteModules
|
|
1985
|
+
};
|
|
1935
1986
|
if (payload.type !== "render") throw new Error("Invalid payload type");
|
|
1987
|
+
globalVar.__reactRouterRouteModules = globalVar.__reactRouterRouteModules ?? {};
|
|
1988
|
+
populateRSCRouteModules(globalVar.__reactRouterRouteModules, payload.matches);
|
|
1936
1989
|
let patches = /* @__PURE__ */ new Map();
|
|
1937
1990
|
payload.patches?.forEach((patch) => {
|
|
1938
1991
|
invariant(patch.parentId, "Invalid patch parentId");
|
|
@@ -1957,7 +2010,7 @@ function createRouterFromPayload({
|
|
|
1957
2010
|
}
|
|
1958
2011
|
return [route];
|
|
1959
2012
|
}, []);
|
|
1960
|
-
globalVar.
|
|
2013
|
+
globalVar.__reactRouterDataRouter = createRouter({
|
|
1961
2014
|
routes,
|
|
1962
2015
|
unstable_getContext,
|
|
1963
2016
|
basename: payload.basename,
|
|
@@ -1995,26 +2048,79 @@ function createRouterFromPayload({
|
|
|
1995
2048
|
},
|
|
1996
2049
|
// FIXME: Pass `build.ssr` into this function
|
|
1997
2050
|
dataStrategy: getRSCSingleFetchDataStrategy(
|
|
1998
|
-
() => globalVar.
|
|
2051
|
+
() => globalVar.__reactRouterDataRouter,
|
|
1999
2052
|
true,
|
|
2000
2053
|
payload.basename,
|
|
2001
2054
|
createFromReadableStream,
|
|
2002
2055
|
fetchImplementation
|
|
2003
2056
|
)
|
|
2004
2057
|
});
|
|
2005
|
-
if (globalVar.
|
|
2058
|
+
if (globalVar.__reactRouterDataRouter.state.initialized) {
|
|
2006
2059
|
globalVar.__routerInitialized = true;
|
|
2007
|
-
globalVar.
|
|
2060
|
+
globalVar.__reactRouterDataRouter.initialize();
|
|
2008
2061
|
} else {
|
|
2009
2062
|
globalVar.__routerInitialized = false;
|
|
2010
2063
|
}
|
|
2011
2064
|
let lastLoaderData = void 0;
|
|
2012
|
-
globalVar.
|
|
2065
|
+
globalVar.__reactRouterDataRouter.subscribe(({ loaderData, actionData }) => {
|
|
2013
2066
|
if (lastLoaderData !== loaderData) {
|
|
2014
2067
|
globalVar.__routerActionID = (globalVar.__routerActionID ?? (globalVar.__routerActionID = 0)) + 1;
|
|
2015
2068
|
}
|
|
2016
2069
|
});
|
|
2017
|
-
|
|
2070
|
+
globalVar.__reactRouterDataRouter._updateRoutesForHMR = (routeUpdateByRouteId) => {
|
|
2071
|
+
const oldRoutes = window.__reactRouterDataRouter.routes;
|
|
2072
|
+
const newRoutes = [];
|
|
2073
|
+
function walkRoutes(routes2, parentId) {
|
|
2074
|
+
return routes2.map((route) => {
|
|
2075
|
+
const routeUpdate = routeUpdateByRouteId.get(route.id);
|
|
2076
|
+
if (routeUpdate) {
|
|
2077
|
+
const {
|
|
2078
|
+
routeModule,
|
|
2079
|
+
hasAction,
|
|
2080
|
+
hasComponent,
|
|
2081
|
+
hasErrorBoundary,
|
|
2082
|
+
hasLoader
|
|
2083
|
+
} = routeUpdate;
|
|
2084
|
+
const newRoute = createRouteFromServerManifest({
|
|
2085
|
+
clientAction: routeModule.clientAction,
|
|
2086
|
+
clientLoader: routeModule.clientLoader,
|
|
2087
|
+
element: route.element,
|
|
2088
|
+
errorElement: route.errorElement,
|
|
2089
|
+
handle: route.handle,
|
|
2090
|
+
hasAction,
|
|
2091
|
+
hasComponent,
|
|
2092
|
+
hasErrorBoundary,
|
|
2093
|
+
hasLoader,
|
|
2094
|
+
hydrateFallbackElement: route.hydrateFallbackElement,
|
|
2095
|
+
id: route.id,
|
|
2096
|
+
index: route.index,
|
|
2097
|
+
links: routeModule.links,
|
|
2098
|
+
meta: routeModule.meta,
|
|
2099
|
+
parentId,
|
|
2100
|
+
path: route.path,
|
|
2101
|
+
shouldRevalidate: routeModule.shouldRevalidate
|
|
2102
|
+
});
|
|
2103
|
+
if (route.children) {
|
|
2104
|
+
newRoute.children = walkRoutes(route.children, route.id);
|
|
2105
|
+
}
|
|
2106
|
+
return newRoute;
|
|
2107
|
+
}
|
|
2108
|
+
const updatedRoute = { ...route };
|
|
2109
|
+
if (route.children) {
|
|
2110
|
+
updatedRoute.children = walkRoutes(route.children, route.id);
|
|
2111
|
+
}
|
|
2112
|
+
return updatedRoute;
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
newRoutes.push(
|
|
2116
|
+
...walkRoutes(oldRoutes, void 0)
|
|
2117
|
+
);
|
|
2118
|
+
window.__reactRouterDataRouter._internalSetRoutes(newRoutes);
|
|
2119
|
+
};
|
|
2120
|
+
return {
|
|
2121
|
+
router: globalVar.__reactRouterDataRouter,
|
|
2122
|
+
routeModules: globalVar.__reactRouterRouteModules
|
|
2123
|
+
};
|
|
2018
2124
|
}
|
|
2019
2125
|
var renderedRoutesContext = unstable_createContext();
|
|
2020
2126
|
function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, createFromReadableStream, fetchImplementation) {
|
|
@@ -2058,7 +2164,7 @@ function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, createFromReada
|
|
|
2058
2164
|
const renderedRoutes = renderedRoutesById.get(match.route.id);
|
|
2059
2165
|
if (renderedRoutes) {
|
|
2060
2166
|
for (const rendered of renderedRoutes) {
|
|
2061
|
-
window.
|
|
2167
|
+
window.__reactRouterDataRouter.patchRoutes(
|
|
2062
2168
|
rendered.parentId ?? null,
|
|
2063
2169
|
[createRouteFromServerManifest(rendered)],
|
|
2064
2170
|
true
|
|
@@ -2132,7 +2238,7 @@ function RSCHydratedRouter({
|
|
|
2132
2238
|
unstable_getContext
|
|
2133
2239
|
}) {
|
|
2134
2240
|
if (payload.type !== "render") throw new Error("Invalid payload type");
|
|
2135
|
-
let router = React4.useMemo(
|
|
2241
|
+
let { router, routeModules } = React4.useMemo(
|
|
2136
2242
|
() => createRouterFromPayload({
|
|
2137
2243
|
payload,
|
|
2138
2244
|
fetchImplementation,
|
|
@@ -2146,11 +2252,14 @@ function RSCHydratedRouter({
|
|
|
2146
2252
|
unstable_getContext
|
|
2147
2253
|
]
|
|
2148
2254
|
);
|
|
2255
|
+
React4.useEffect(() => {
|
|
2256
|
+
setIsHydrated();
|
|
2257
|
+
}, []);
|
|
2149
2258
|
React4.useLayoutEffect(() => {
|
|
2150
2259
|
const globalVar = window;
|
|
2151
2260
|
if (!globalVar.__routerInitialized) {
|
|
2152
2261
|
globalVar.__routerInitialized = true;
|
|
2153
|
-
globalVar.
|
|
2262
|
+
globalVar.__reactRouterDataRouter.initialize();
|
|
2154
2263
|
}
|
|
2155
2264
|
}, []);
|
|
2156
2265
|
let [location2, setLocation] = React4.useState(router.state.location);
|
|
@@ -2216,7 +2325,7 @@ function RSCHydratedRouter({
|
|
|
2216
2325
|
unstable_middleware: false,
|
|
2217
2326
|
unstable_subResourceIntegrity: false
|
|
2218
2327
|
},
|
|
2219
|
-
isSpaMode:
|
|
2328
|
+
isSpaMode: false,
|
|
2220
2329
|
ssr: true,
|
|
2221
2330
|
criticalCss: "",
|
|
2222
2331
|
manifest: {
|
|
@@ -2229,7 +2338,7 @@ function RSCHydratedRouter({
|
|
|
2229
2338
|
}
|
|
2230
2339
|
},
|
|
2231
2340
|
routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
|
|
2232
|
-
routeModules
|
|
2341
|
+
routeModules
|
|
2233
2342
|
};
|
|
2234
2343
|
return /* @__PURE__ */ React4.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React4.createElement(RSCRouterGlobalErrorBoundary, { location: location2 }, /* @__PURE__ */ React4.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React4.createElement(RouterProvider, { router, flushSync: ReactDOM.flushSync }))));
|
|
2235
2344
|
}
|
|
@@ -2242,6 +2351,8 @@ function createRouteFromServerManifest(match, payload) {
|
|
|
2242
2351
|
// the server loader flow regardless of whether the client loader calls
|
|
2243
2352
|
// `serverLoader` or not, otherwise we'll have nothing to render.
|
|
2244
2353
|
match.hasComponent && !match.element;
|
|
2354
|
+
invariant(window.__reactRouterRouteModules);
|
|
2355
|
+
populateRSCRouteModules(window.__reactRouterRouteModules, match);
|
|
2245
2356
|
let dataRoute = {
|
|
2246
2357
|
id: match.id,
|
|
2247
2358
|
element: match.element,
|
|
@@ -2337,7 +2448,10 @@ function getManifestUrl(paths) {
|
|
|
2337
2448
|
return new URL(`${paths[0]}.manifest`, window.location.origin);
|
|
2338
2449
|
}
|
|
2339
2450
|
const globalVar = window;
|
|
2340
|
-
let basename = (globalVar.
|
|
2451
|
+
let basename = (globalVar.__reactRouterDataRouter.basename ?? "").replace(
|
|
2452
|
+
/^\/|\/$/g,
|
|
2453
|
+
""
|
|
2454
|
+
);
|
|
2341
2455
|
let url = new URL(`${basename}/.manifest`, window.location.origin);
|
|
2342
2456
|
paths.sort().forEach((path) => url.searchParams.append("p", path));
|
|
2343
2457
|
return url;
|
|
@@ -2363,7 +2477,7 @@ async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fet
|
|
|
2363
2477
|
}
|
|
2364
2478
|
paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
|
|
2365
2479
|
payload.patches.forEach((p) => {
|
|
2366
|
-
window.
|
|
2480
|
+
window.__reactRouterDataRouter.patchRoutes(
|
|
2367
2481
|
p.parentId ?? null,
|
|
2368
2482
|
[createRouteFromServerManifest(p)]
|
|
2369
2483
|
);
|
|
@@ -2640,7 +2754,7 @@ function RSCStaticRouter({ getPayload }) {
|
|
|
2640
2754
|
}
|
|
2641
2755
|
},
|
|
2642
2756
|
routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
|
|
2643
|
-
routeModules:
|
|
2757
|
+
routeModules: createRSCRouteModules(payload)
|
|
2644
2758
|
};
|
|
2645
2759
|
return /* @__PURE__ */ React5.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React5.createElement(RSCRouterGlobalErrorBoundary, { location: payload.location }, /* @__PURE__ */ React5.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React5.createElement(
|
|
2646
2760
|
StaticRouterProvider,
|