react-router 7.2.0-pre.6 → 7.3.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 +268 -28
- package/dist/development/{chunk-TEULL7XU.mjs → chunk-W5LWFPOT.mjs} +851 -336
- package/dist/development/dom-export.d.mts +13 -3
- package/dist/development/dom-export.d.ts +13 -3
- package/dist/development/dom-export.js +371 -79
- package/dist/development/dom-export.mjs +14 -5
- package/dist/development/{fog-of-war-Cm1iXIp7.d.ts → fog-of-war-CvttGpNz.d.ts} +93 -9
- package/dist/{production/fog-of-war-Cm1iXIp7.d.ts → development/fog-of-war-Da8gpnoZ.d.mts} +93 -9
- package/dist/{production/data-CQbyyGzl.d.mts → development/future-ldDp5FKH.d.mts} +11 -1
- package/dist/development/{data-CQbyyGzl.d.mts → future-ldDp5FKH.d.ts} +11 -1
- package/dist/development/index.d.mts +16 -14
- package/dist/development/index.d.ts +16 -14
- package/dist/development/index.js +853 -336
- package/dist/development/index.mjs +6 -2
- package/dist/development/lib/types/route-module.d.mts +24 -6
- package/dist/development/lib/types/route-module.d.ts +24 -6
- package/dist/development/lib/types/route-module.js +1 -1
- package/dist/development/lib/types/route-module.mjs +1 -1
- package/dist/{production/route-data-BmvbmBej.d.mts → development/route-data-H2S3hwhf.d.mts} +66 -13
- package/dist/development/{route-data-BmvbmBej.d.mts → route-data-H2S3hwhf.d.ts} +66 -13
- package/dist/production/{chunk-ZQLTZ2R5.mjs → chunk-ZITGHOQF.mjs} +851 -336
- package/dist/production/dom-export.d.mts +13 -3
- package/dist/production/dom-export.d.ts +13 -3
- package/dist/production/dom-export.js +371 -79
- package/dist/production/dom-export.mjs +14 -5
- package/dist/production/{fog-of-war-BALYJxf_.d.mts → fog-of-war-CvttGpNz.d.ts} +93 -9
- package/dist/{development/fog-of-war-BALYJxf_.d.mts → production/fog-of-war-Da8gpnoZ.d.mts} +93 -9
- package/dist/{development/data-CQbyyGzl.d.ts → production/future-ldDp5FKH.d.mts} +11 -1
- package/dist/production/{data-CQbyyGzl.d.ts → future-ldDp5FKH.d.ts} +11 -1
- package/dist/production/index.d.mts +16 -14
- package/dist/production/index.d.ts +16 -14
- package/dist/production/index.js +853 -336
- package/dist/production/index.mjs +6 -2
- package/dist/production/lib/types/route-module.d.mts +24 -6
- package/dist/production/lib/types/route-module.d.ts +24 -6
- package/dist/production/lib/types/route-module.js +1 -1
- package/dist/production/lib/types/route-module.mjs +1 -1
- package/dist/{development/route-data-BmvbmBej.d.ts → production/route-data-H2S3hwhf.d.mts} +66 -13
- package/dist/production/{route-data-BmvbmBej.d.ts → route-data-H2S3hwhf.d.ts} +66 -13
- package/package.json +3 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v7.
|
|
2
|
+
* react-router v7.3.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -15,6 +15,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
15
15
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
16
|
var __getProtoOf = Object.getPrototypeOf;
|
|
17
17
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
18
|
+
var __typeError = (msg) => {
|
|
19
|
+
throw TypeError(msg);
|
|
20
|
+
};
|
|
18
21
|
var __export = (target, all) => {
|
|
19
22
|
for (var name in all)
|
|
20
23
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -36,6 +39,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
39
|
mod
|
|
37
40
|
));
|
|
38
41
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
43
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
44
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
39
45
|
|
|
40
46
|
// dom-export.ts
|
|
41
47
|
var dom_export_exports = {};
|
|
@@ -245,6 +251,30 @@ function getUrlBasedHistory(getLocation, createHref, validateLocation, options =
|
|
|
245
251
|
}
|
|
246
252
|
|
|
247
253
|
// lib/router/utils.ts
|
|
254
|
+
var _map;
|
|
255
|
+
var unstable_RouterContextProvider = class {
|
|
256
|
+
constructor(init) {
|
|
257
|
+
__privateAdd(this, _map, /* @__PURE__ */ new Map());
|
|
258
|
+
if (init) {
|
|
259
|
+
for (let [context, value] of init) {
|
|
260
|
+
this.set(context, value);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
get(context) {
|
|
265
|
+
if (__privateGet(this, _map).has(context)) {
|
|
266
|
+
return __privateGet(this, _map).get(context);
|
|
267
|
+
}
|
|
268
|
+
if (context.defaultValue !== void 0) {
|
|
269
|
+
return context.defaultValue;
|
|
270
|
+
}
|
|
271
|
+
throw new Error("No value found for context");
|
|
272
|
+
}
|
|
273
|
+
set(context, value) {
|
|
274
|
+
__privateGet(this, _map).set(context, value);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
_map = new WeakMap();
|
|
248
278
|
var immutableRouteKeys = /* @__PURE__ */ new Set([
|
|
249
279
|
"lazy",
|
|
250
280
|
"caseSensitive",
|
|
@@ -764,9 +794,9 @@ function createRouter(init) {
|
|
|
764
794
|
);
|
|
765
795
|
let inFlightDataRoutes;
|
|
766
796
|
let basename = init.basename || "/";
|
|
767
|
-
let dataStrategyImpl = init.dataStrategy ||
|
|
768
|
-
let patchRoutesOnNavigationImpl = init.patchRoutesOnNavigation;
|
|
797
|
+
let dataStrategyImpl = init.dataStrategy || defaultDataStrategyWithMiddleware;
|
|
769
798
|
let future = {
|
|
799
|
+
unstable_middleware: false,
|
|
770
800
|
...init.future
|
|
771
801
|
};
|
|
772
802
|
let unlistenHistory = null;
|
|
@@ -778,7 +808,7 @@ function createRouter(init) {
|
|
|
778
808
|
let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
|
|
779
809
|
let initialMatchesIsFOW = false;
|
|
780
810
|
let initialErrors = null;
|
|
781
|
-
if (initialMatches == null && !
|
|
811
|
+
if (initialMatches == null && !init.patchRoutesOnNavigation) {
|
|
782
812
|
let error = getInternalRouterError(404, {
|
|
783
813
|
pathname: init.history.location.pathname
|
|
784
814
|
});
|
|
@@ -1209,6 +1239,9 @@ function createRouter(init) {
|
|
|
1209
1239
|
pendingNavigationController.signal,
|
|
1210
1240
|
opts && opts.submission
|
|
1211
1241
|
);
|
|
1242
|
+
let scopedContext = new unstable_RouterContextProvider(
|
|
1243
|
+
init.unstable_getContext ? await init.unstable_getContext() : void 0
|
|
1244
|
+
);
|
|
1212
1245
|
let pendingActionResult;
|
|
1213
1246
|
if (opts && opts.pendingError) {
|
|
1214
1247
|
pendingActionResult = [
|
|
@@ -1221,6 +1254,7 @@ function createRouter(init) {
|
|
|
1221
1254
|
location,
|
|
1222
1255
|
opts.submission,
|
|
1223
1256
|
matches,
|
|
1257
|
+
scopedContext,
|
|
1224
1258
|
fogOfWar.active,
|
|
1225
1259
|
{ replace: opts.replace, flushSync: flushSync2 }
|
|
1226
1260
|
);
|
|
@@ -1261,6 +1295,7 @@ function createRouter(init) {
|
|
|
1261
1295
|
request,
|
|
1262
1296
|
location,
|
|
1263
1297
|
matches,
|
|
1298
|
+
scopedContext,
|
|
1264
1299
|
fogOfWar.active,
|
|
1265
1300
|
loadingNavigation,
|
|
1266
1301
|
opts && opts.submission,
|
|
@@ -1281,7 +1316,7 @@ function createRouter(init) {
|
|
|
1281
1316
|
errors
|
|
1282
1317
|
});
|
|
1283
1318
|
}
|
|
1284
|
-
async function handleAction(request, location, submission, matches, isFogOfWar, opts = {}) {
|
|
1319
|
+
async function handleAction(request, location, submission, matches, scopedContext, isFogOfWar, opts = {}) {
|
|
1285
1320
|
interruptActiveLoads();
|
|
1286
1321
|
let navigation = getSubmittingNavigation(location, submission);
|
|
1287
1322
|
updateState({ navigation }, { flushSync: opts.flushSync === true });
|
|
@@ -1337,13 +1372,21 @@ function createRouter(init) {
|
|
|
1337
1372
|
} else {
|
|
1338
1373
|
let results = await callDataStrategy(
|
|
1339
1374
|
"action",
|
|
1340
|
-
state,
|
|
1341
1375
|
request,
|
|
1342
1376
|
[actionMatch],
|
|
1343
1377
|
matches,
|
|
1378
|
+
scopedContext,
|
|
1344
1379
|
null
|
|
1345
1380
|
);
|
|
1346
1381
|
result = results[actionMatch.route.id];
|
|
1382
|
+
if (!result) {
|
|
1383
|
+
for (let match of matches) {
|
|
1384
|
+
if (results[match.route.id]) {
|
|
1385
|
+
result = results[match.route.id];
|
|
1386
|
+
break;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1347
1390
|
if (request.signal.aborted) {
|
|
1348
1391
|
return { shortCircuited: true };
|
|
1349
1392
|
}
|
|
@@ -1381,7 +1424,7 @@ function createRouter(init) {
|
|
|
1381
1424
|
pendingActionResult: [actionMatch.route.id, result]
|
|
1382
1425
|
};
|
|
1383
1426
|
}
|
|
1384
|
-
async function handleLoaders(request, location, matches, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync2, pendingActionResult) {
|
|
1427
|
+
async function handleLoaders(request, location, matches, scopedContext, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync2, pendingActionResult) {
|
|
1385
1428
|
let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
|
|
1386
1429
|
let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
|
|
1387
1430
|
let shouldUpdateNavigationState = !isUninterruptedRevalidation && !initialHydration;
|
|
@@ -1491,11 +1534,11 @@ function createRouter(init) {
|
|
|
1491
1534
|
);
|
|
1492
1535
|
}
|
|
1493
1536
|
let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
|
1494
|
-
state,
|
|
1495
1537
|
matches,
|
|
1496
1538
|
matchesToLoad,
|
|
1497
1539
|
revalidatingFetchers,
|
|
1498
|
-
request
|
|
1540
|
+
request,
|
|
1541
|
+
scopedContext
|
|
1499
1542
|
);
|
|
1500
1543
|
if (request.signal.aborted) {
|
|
1501
1544
|
return { shortCircuited: true };
|
|
@@ -1603,6 +1646,9 @@ function createRouter(init) {
|
|
|
1603
1646
|
return;
|
|
1604
1647
|
}
|
|
1605
1648
|
let match = getTargetMatch(matches, path);
|
|
1649
|
+
let scopedContext = new unstable_RouterContextProvider(
|
|
1650
|
+
init.unstable_getContext ? await init.unstable_getContext() : void 0
|
|
1651
|
+
);
|
|
1606
1652
|
let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1607
1653
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
1608
1654
|
await handleFetcherAction(
|
|
@@ -1611,6 +1657,7 @@ function createRouter(init) {
|
|
|
1611
1657
|
path,
|
|
1612
1658
|
match,
|
|
1613
1659
|
matches,
|
|
1660
|
+
scopedContext,
|
|
1614
1661
|
fogOfWar.active,
|
|
1615
1662
|
flushSync2,
|
|
1616
1663
|
preventScrollReset,
|
|
@@ -1625,13 +1672,14 @@ function createRouter(init) {
|
|
|
1625
1672
|
path,
|
|
1626
1673
|
match,
|
|
1627
1674
|
matches,
|
|
1675
|
+
scopedContext,
|
|
1628
1676
|
fogOfWar.active,
|
|
1629
1677
|
flushSync2,
|
|
1630
1678
|
preventScrollReset,
|
|
1631
1679
|
submission
|
|
1632
1680
|
);
|
|
1633
1681
|
}
|
|
1634
|
-
async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync2, preventScrollReset, submission) {
|
|
1682
|
+
async function handleFetcherAction(key, routeId, path, match, requestMatches, scopedContext, isFogOfWar, flushSync2, preventScrollReset, submission) {
|
|
1635
1683
|
interruptActiveLoads();
|
|
1636
1684
|
fetchLoadMatches.delete(key);
|
|
1637
1685
|
function detectAndHandle405Error(m) {
|
|
@@ -1664,7 +1712,8 @@ function createRouter(init) {
|
|
|
1664
1712
|
let discoverResult = await discoverRoutes(
|
|
1665
1713
|
requestMatches,
|
|
1666
1714
|
path,
|
|
1667
|
-
fetchRequest.signal
|
|
1715
|
+
fetchRequest.signal,
|
|
1716
|
+
key
|
|
1668
1717
|
);
|
|
1669
1718
|
if (discoverResult.type === "aborted") {
|
|
1670
1719
|
return;
|
|
@@ -1691,10 +1740,10 @@ function createRouter(init) {
|
|
|
1691
1740
|
let originatingLoadId = incrementingLoadId;
|
|
1692
1741
|
let actionResults = await callDataStrategy(
|
|
1693
1742
|
"action",
|
|
1694
|
-
state,
|
|
1695
1743
|
fetchRequest,
|
|
1696
1744
|
[match],
|
|
1697
1745
|
requestMatches,
|
|
1746
|
+
scopedContext,
|
|
1698
1747
|
key
|
|
1699
1748
|
);
|
|
1700
1749
|
let actionResult = actionResults[match.route.id];
|
|
@@ -1778,11 +1827,11 @@ function createRouter(init) {
|
|
|
1778
1827
|
abortPendingFetchRevalidations
|
|
1779
1828
|
);
|
|
1780
1829
|
let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
|
1781
|
-
state,
|
|
1782
1830
|
matches,
|
|
1783
1831
|
matchesToLoad,
|
|
1784
1832
|
revalidatingFetchers,
|
|
1785
|
-
revalidationRequest
|
|
1833
|
+
revalidationRequest,
|
|
1834
|
+
scopedContext
|
|
1786
1835
|
);
|
|
1787
1836
|
if (abortController.signal.aborted) {
|
|
1788
1837
|
return;
|
|
@@ -1849,7 +1898,7 @@ function createRouter(init) {
|
|
|
1849
1898
|
isRevalidationRequired = false;
|
|
1850
1899
|
}
|
|
1851
1900
|
}
|
|
1852
|
-
async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync2, preventScrollReset, submission) {
|
|
1901
|
+
async function handleFetcherLoader(key, routeId, path, match, matches, scopedContext, isFogOfWar, flushSync2, preventScrollReset, submission) {
|
|
1853
1902
|
let existingFetcher = state.fetchers.get(key);
|
|
1854
1903
|
updateFetcherState(
|
|
1855
1904
|
key,
|
|
@@ -1869,7 +1918,8 @@ function createRouter(init) {
|
|
|
1869
1918
|
let discoverResult = await discoverRoutes(
|
|
1870
1919
|
matches,
|
|
1871
1920
|
path,
|
|
1872
|
-
fetchRequest.signal
|
|
1921
|
+
fetchRequest.signal,
|
|
1922
|
+
key
|
|
1873
1923
|
);
|
|
1874
1924
|
if (discoverResult.type === "aborted") {
|
|
1875
1925
|
return;
|
|
@@ -1893,10 +1943,10 @@ function createRouter(init) {
|
|
|
1893
1943
|
let originatingLoadId = incrementingLoadId;
|
|
1894
1944
|
let results = await callDataStrategy(
|
|
1895
1945
|
"loader",
|
|
1896
|
-
state,
|
|
1897
1946
|
fetchRequest,
|
|
1898
1947
|
[match],
|
|
1899
1948
|
matches,
|
|
1949
|
+
scopedContext,
|
|
1900
1950
|
key
|
|
1901
1951
|
);
|
|
1902
1952
|
let result = results[match.route.id];
|
|
@@ -1998,20 +2048,21 @@ function createRouter(init) {
|
|
|
1998
2048
|
});
|
|
1999
2049
|
}
|
|
2000
2050
|
}
|
|
2001
|
-
async function callDataStrategy(type,
|
|
2051
|
+
async function callDataStrategy(type, request, matchesToLoad, matches, scopedContext, fetcherKey) {
|
|
2002
2052
|
let results;
|
|
2003
2053
|
let dataResults = {};
|
|
2004
2054
|
try {
|
|
2005
2055
|
results = await callDataStrategyImpl(
|
|
2006
2056
|
dataStrategyImpl,
|
|
2007
2057
|
type,
|
|
2008
|
-
state2,
|
|
2009
2058
|
request,
|
|
2010
2059
|
matchesToLoad,
|
|
2011
2060
|
matches,
|
|
2012
2061
|
fetcherKey,
|
|
2013
2062
|
manifest,
|
|
2014
|
-
mapRouteProperties2
|
|
2063
|
+
mapRouteProperties2,
|
|
2064
|
+
scopedContext,
|
|
2065
|
+
future.unstable_middleware
|
|
2015
2066
|
);
|
|
2016
2067
|
} catch (e) {
|
|
2017
2068
|
matchesToLoad.forEach((m) => {
|
|
@@ -2043,13 +2094,13 @@ function createRouter(init) {
|
|
|
2043
2094
|
}
|
|
2044
2095
|
return dataResults;
|
|
2045
2096
|
}
|
|
2046
|
-
async function callLoadersAndMaybeResolveData(
|
|
2097
|
+
async function callLoadersAndMaybeResolveData(matches, matchesToLoad, fetchersToLoad, request, scopedContext) {
|
|
2047
2098
|
let loaderResultsPromise = callDataStrategy(
|
|
2048
2099
|
"loader",
|
|
2049
|
-
state2,
|
|
2050
2100
|
request,
|
|
2051
2101
|
matchesToLoad,
|
|
2052
2102
|
matches,
|
|
2103
|
+
scopedContext,
|
|
2053
2104
|
null
|
|
2054
2105
|
);
|
|
2055
2106
|
let fetcherResultsPromise = Promise.all(
|
|
@@ -2057,10 +2108,10 @@ function createRouter(init) {
|
|
|
2057
2108
|
if (f.matches && f.match && f.controller) {
|
|
2058
2109
|
let results = await callDataStrategy(
|
|
2059
2110
|
"loader",
|
|
2060
|
-
state2,
|
|
2061
2111
|
createClientSideRequest(init.history, f.path, f.controller.signal),
|
|
2062
2112
|
[f.match],
|
|
2063
2113
|
f.matches,
|
|
2114
|
+
scopedContext,
|
|
2064
2115
|
f.key
|
|
2065
2116
|
);
|
|
2066
2117
|
let result = results[f.match.route.id];
|
|
@@ -2282,7 +2333,7 @@ function createRouter(init) {
|
|
|
2282
2333
|
return null;
|
|
2283
2334
|
}
|
|
2284
2335
|
function checkFogOfWar(matches, routesToUse, pathname) {
|
|
2285
|
-
if (
|
|
2336
|
+
if (init.patchRoutesOnNavigation) {
|
|
2286
2337
|
if (!matches) {
|
|
2287
2338
|
let fogMatches = matchRoutesImpl(
|
|
2288
2339
|
routesToUse,
|
|
@@ -2305,8 +2356,8 @@ function createRouter(init) {
|
|
|
2305
2356
|
}
|
|
2306
2357
|
return { active: false, matches: null };
|
|
2307
2358
|
}
|
|
2308
|
-
async function discoverRoutes(matches, pathname, signal) {
|
|
2309
|
-
if (!
|
|
2359
|
+
async function discoverRoutes(matches, pathname, signal, fetcherKey) {
|
|
2360
|
+
if (!init.patchRoutesOnNavigation) {
|
|
2310
2361
|
return { type: "success", matches };
|
|
2311
2362
|
}
|
|
2312
2363
|
let partialMatches = matches;
|
|
@@ -2315,10 +2366,11 @@ function createRouter(init) {
|
|
|
2315
2366
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
2316
2367
|
let localManifest = manifest;
|
|
2317
2368
|
try {
|
|
2318
|
-
await
|
|
2369
|
+
await init.patchRoutesOnNavigation({
|
|
2319
2370
|
signal,
|
|
2320
2371
|
path: pathname,
|
|
2321
2372
|
matches: partialMatches,
|
|
2373
|
+
fetcherKey,
|
|
2322
2374
|
patch: (routeId, children) => {
|
|
2323
2375
|
if (signal.aborted) return;
|
|
2324
2376
|
patchRoutesImpl(
|
|
@@ -2803,20 +2855,143 @@ async function loadLazyRouteModule(route, mapRouteProperties2, manifest) {
|
|
|
2803
2855
|
lazy: void 0
|
|
2804
2856
|
});
|
|
2805
2857
|
}
|
|
2806
|
-
async function defaultDataStrategy({
|
|
2807
|
-
matches
|
|
2808
|
-
|
|
2809
|
-
let matchesToLoad = matches.filter((m) => m.shouldLoad);
|
|
2858
|
+
async function defaultDataStrategy(args) {
|
|
2859
|
+
let matchesToLoad = args.matches.filter((m) => m.shouldLoad);
|
|
2860
|
+
let keyedResults = {};
|
|
2810
2861
|
let results = await Promise.all(matchesToLoad.map((m) => m.resolve()));
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2862
|
+
results.forEach((result, i) => {
|
|
2863
|
+
keyedResults[matchesToLoad[i].route.id] = result;
|
|
2864
|
+
});
|
|
2865
|
+
return keyedResults;
|
|
2866
|
+
}
|
|
2867
|
+
async function defaultDataStrategyWithMiddleware(args) {
|
|
2868
|
+
if (!args.matches.some((m) => m.route.unstable_middleware)) {
|
|
2869
|
+
return defaultDataStrategy(args);
|
|
2870
|
+
}
|
|
2871
|
+
let lastIndex = args.matches.length - 1;
|
|
2872
|
+
for (let i = lastIndex; i >= 0; i--) {
|
|
2873
|
+
if (args.matches[i].shouldLoad) {
|
|
2874
|
+
lastIndex = i;
|
|
2875
|
+
break;
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
let results = await runMiddlewarePipeline(
|
|
2879
|
+
args,
|
|
2880
|
+
lastIndex,
|
|
2881
|
+
false,
|
|
2882
|
+
async (keyedResults) => {
|
|
2883
|
+
Object.assign(keyedResults, await defaultDataStrategy(args));
|
|
2884
|
+
},
|
|
2885
|
+
(e, keyedResults) => {
|
|
2886
|
+
Object.assign(keyedResults, {
|
|
2887
|
+
[e.routeId]: { type: "error", result: e.error }
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2814
2890
|
);
|
|
2891
|
+
return results;
|
|
2892
|
+
}
|
|
2893
|
+
async function runMiddlewarePipeline({
|
|
2894
|
+
request,
|
|
2895
|
+
params,
|
|
2896
|
+
context,
|
|
2897
|
+
matches
|
|
2898
|
+
}, lastIndex, propagateResult, handler, errorHandler) {
|
|
2899
|
+
let middlewareState = {
|
|
2900
|
+
keyedResults: {},
|
|
2901
|
+
propagateResult
|
|
2902
|
+
};
|
|
2903
|
+
try {
|
|
2904
|
+
let result = await callRouteMiddleware(
|
|
2905
|
+
matches.slice(0, lastIndex + 1).flatMap(
|
|
2906
|
+
(m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
|
|
2907
|
+
),
|
|
2908
|
+
0,
|
|
2909
|
+
{ request, params, context },
|
|
2910
|
+
middlewareState,
|
|
2911
|
+
handler
|
|
2912
|
+
);
|
|
2913
|
+
return middlewareState.propagateResult ? result : middlewareState.keyedResults;
|
|
2914
|
+
} catch (e) {
|
|
2915
|
+
if (!(e instanceof MiddlewareError)) {
|
|
2916
|
+
throw e;
|
|
2917
|
+
}
|
|
2918
|
+
let result = await errorHandler(e, middlewareState.keyedResults);
|
|
2919
|
+
return middlewareState.propagateResult ? result : middlewareState.keyedResults;
|
|
2920
|
+
}
|
|
2815
2921
|
}
|
|
2816
|
-
|
|
2922
|
+
var MiddlewareError = class {
|
|
2923
|
+
constructor(routeId, error) {
|
|
2924
|
+
this.routeId = routeId;
|
|
2925
|
+
this.error = error;
|
|
2926
|
+
}
|
|
2927
|
+
};
|
|
2928
|
+
async function callRouteMiddleware(middlewares, idx, args, middlewareState, handler) {
|
|
2929
|
+
let { request } = args;
|
|
2930
|
+
if (request.signal.aborted) {
|
|
2931
|
+
if (request.signal.reason) {
|
|
2932
|
+
throw request.signal.reason;
|
|
2933
|
+
}
|
|
2934
|
+
throw new Error(
|
|
2935
|
+
`Request aborted without an \`AbortSignal.reason\`: ${request.method} ${request.url}`
|
|
2936
|
+
);
|
|
2937
|
+
}
|
|
2938
|
+
let tuple = middlewares[idx];
|
|
2939
|
+
if (!tuple) {
|
|
2940
|
+
let result = await handler(middlewareState.keyedResults);
|
|
2941
|
+
return result;
|
|
2942
|
+
}
|
|
2943
|
+
let [routeId, middleware] = tuple;
|
|
2944
|
+
let nextCalled = false;
|
|
2945
|
+
let nextResult = void 0;
|
|
2946
|
+
let next = async () => {
|
|
2947
|
+
if (nextCalled) {
|
|
2948
|
+
throw new Error("You may only call `next()` once per middleware");
|
|
2949
|
+
}
|
|
2950
|
+
nextCalled = true;
|
|
2951
|
+
let result = await callRouteMiddleware(
|
|
2952
|
+
middlewares,
|
|
2953
|
+
idx + 1,
|
|
2954
|
+
args,
|
|
2955
|
+
middlewareState,
|
|
2956
|
+
handler
|
|
2957
|
+
);
|
|
2958
|
+
if (middlewareState.propagateResult) {
|
|
2959
|
+
nextResult = result;
|
|
2960
|
+
return nextResult;
|
|
2961
|
+
}
|
|
2962
|
+
};
|
|
2963
|
+
try {
|
|
2964
|
+
let result = await middleware(
|
|
2965
|
+
{
|
|
2966
|
+
request: args.request,
|
|
2967
|
+
params: args.params,
|
|
2968
|
+
context: args.context
|
|
2969
|
+
},
|
|
2970
|
+
next
|
|
2971
|
+
);
|
|
2972
|
+
if (nextCalled) {
|
|
2973
|
+
if (result === void 0) {
|
|
2974
|
+
return nextResult;
|
|
2975
|
+
} else {
|
|
2976
|
+
return result;
|
|
2977
|
+
}
|
|
2978
|
+
} else {
|
|
2979
|
+
return next();
|
|
2980
|
+
}
|
|
2981
|
+
} catch (e) {
|
|
2982
|
+
if (e instanceof MiddlewareError) {
|
|
2983
|
+
throw e;
|
|
2984
|
+
}
|
|
2985
|
+
throw new MiddlewareError(routeId, e);
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLoad, matches, fetcherKey, manifest, mapRouteProperties2, scopedContext, enableMiddleware) {
|
|
2817
2989
|
let loadRouteDefinitionsPromises = matches.map(
|
|
2818
2990
|
(m) => m.route.lazy ? loadLazyRouteModule(m.route, mapRouteProperties2, manifest) : void 0
|
|
2819
2991
|
);
|
|
2992
|
+
if (enableMiddleware) {
|
|
2993
|
+
await Promise.all(loadRouteDefinitionsPromises);
|
|
2994
|
+
}
|
|
2820
2995
|
let dsMatches = matches.map((match, i) => {
|
|
2821
2996
|
let loadRoutePromise = loadRouteDefinitionsPromises[i];
|
|
2822
2997
|
let shouldLoad = matchesToLoad.some((m) => m.route.id === match.route.id);
|
|
@@ -2830,7 +3005,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matc
|
|
|
2830
3005
|
match,
|
|
2831
3006
|
loadRoutePromise,
|
|
2832
3007
|
handlerOverride,
|
|
2833
|
-
|
|
3008
|
+
scopedContext
|
|
2834
3009
|
) : Promise.resolve({ type: "data" /* data */, result: void 0 });
|
|
2835
3010
|
};
|
|
2836
3011
|
return {
|
|
@@ -2844,7 +3019,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matc
|
|
|
2844
3019
|
request,
|
|
2845
3020
|
params: matches[0].params,
|
|
2846
3021
|
fetcherKey,
|
|
2847
|
-
context:
|
|
3022
|
+
context: scopedContext
|
|
2848
3023
|
});
|
|
2849
3024
|
try {
|
|
2850
3025
|
await Promise.all(loadRouteDefinitionsPromises);
|
|
@@ -2852,7 +3027,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matc
|
|
|
2852
3027
|
}
|
|
2853
3028
|
return results;
|
|
2854
3029
|
}
|
|
2855
|
-
async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride,
|
|
3030
|
+
async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride, scopedContext) {
|
|
2856
3031
|
let result;
|
|
2857
3032
|
let onReject;
|
|
2858
3033
|
let runHandler = (handler) => {
|
|
@@ -2872,7 +3047,7 @@ async function callLoaderOrAction(type, request, match, loadRoutePromise, handle
|
|
|
2872
3047
|
{
|
|
2873
3048
|
request,
|
|
2874
3049
|
params: match.params,
|
|
2875
|
-
context:
|
|
3050
|
+
context: scopedContext
|
|
2876
3051
|
},
|
|
2877
3052
|
...ctx !== void 0 ? [ctx] : []
|
|
2878
3053
|
);
|
|
@@ -4353,55 +4528,103 @@ async function createRequestInit(request) {
|
|
|
4353
4528
|
|
|
4354
4529
|
// lib/dom/ssr/single-fetch.tsx
|
|
4355
4530
|
var SingleFetchRedirectSymbol = Symbol("SingleFetchRedirect");
|
|
4356
|
-
function
|
|
4357
|
-
|
|
4531
|
+
function middlewareErrorHandler(e, keyedResults) {
|
|
4532
|
+
Object.assign(keyedResults, {
|
|
4533
|
+
[e.routeId]: { type: "error", result: e.error }
|
|
4534
|
+
});
|
|
4535
|
+
}
|
|
4536
|
+
function getSingleFetchDataStrategy(manifest, routeModules, ssr, basename, getRouter) {
|
|
4537
|
+
return async (args) => {
|
|
4538
|
+
let { request, matches, fetcherKey } = args;
|
|
4358
4539
|
if (request.method !== "GET") {
|
|
4359
|
-
return
|
|
4540
|
+
return runMiddlewarePipeline(
|
|
4541
|
+
args,
|
|
4542
|
+
matches.findIndex((m) => m.shouldLoad),
|
|
4543
|
+
false,
|
|
4544
|
+
async (keyedResults) => {
|
|
4545
|
+
let results = await singleFetchActionStrategy(
|
|
4546
|
+
request,
|
|
4547
|
+
matches,
|
|
4548
|
+
basename
|
|
4549
|
+
);
|
|
4550
|
+
Object.assign(keyedResults, results);
|
|
4551
|
+
},
|
|
4552
|
+
middlewareErrorHandler
|
|
4553
|
+
);
|
|
4360
4554
|
}
|
|
4361
4555
|
if (!ssr) {
|
|
4362
4556
|
let foundRevalidatingServerLoader = matches.some(
|
|
4363
4557
|
(m) => m.shouldLoad && manifest.routes[m.route.id]?.hasLoader && !manifest.routes[m.route.id]?.hasClientLoader
|
|
4364
4558
|
);
|
|
4365
4559
|
if (!foundRevalidatingServerLoader) {
|
|
4366
|
-
let
|
|
4367
|
-
let
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4560
|
+
let tailIdx = [...matches].reverse().findIndex((m) => m.shouldLoad);
|
|
4561
|
+
let lowestLoadingIndex2 = tailIdx < 0 ? 0 : matches.length - 1 - tailIdx;
|
|
4562
|
+
return runMiddlewarePipeline(
|
|
4563
|
+
args,
|
|
4564
|
+
lowestLoadingIndex2,
|
|
4565
|
+
false,
|
|
4566
|
+
async (keyedResults) => {
|
|
4567
|
+
let results = await nonSsrStrategy(
|
|
4568
|
+
manifest,
|
|
4569
|
+
request,
|
|
4570
|
+
matches,
|
|
4571
|
+
basename
|
|
4572
|
+
);
|
|
4573
|
+
Object.assign(keyedResults, results);
|
|
4574
|
+
},
|
|
4575
|
+
middlewareErrorHandler
|
|
4381
4576
|
);
|
|
4382
|
-
return results;
|
|
4383
4577
|
}
|
|
4384
4578
|
}
|
|
4385
4579
|
if (fetcherKey) {
|
|
4386
|
-
return
|
|
4580
|
+
return runMiddlewarePipeline(
|
|
4581
|
+
args,
|
|
4582
|
+
matches.findIndex((m) => m.shouldLoad),
|
|
4583
|
+
false,
|
|
4584
|
+
async (keyedResults) => {
|
|
4585
|
+
let results = await singleFetchLoaderFetcherStrategy(
|
|
4586
|
+
request,
|
|
4587
|
+
matches,
|
|
4588
|
+
basename
|
|
4589
|
+
);
|
|
4590
|
+
Object.assign(keyedResults, results);
|
|
4591
|
+
},
|
|
4592
|
+
middlewareErrorHandler
|
|
4593
|
+
);
|
|
4387
4594
|
}
|
|
4388
|
-
|
|
4595
|
+
let lowestLoadingIndex = getLowestLoadingIndex(
|
|
4389
4596
|
manifest,
|
|
4390
4597
|
routeModules,
|
|
4391
|
-
ssr,
|
|
4392
4598
|
getRouter(),
|
|
4393
|
-
request,
|
|
4394
4599
|
matches
|
|
4395
4600
|
);
|
|
4601
|
+
return runMiddlewarePipeline(
|
|
4602
|
+
args,
|
|
4603
|
+
lowestLoadingIndex,
|
|
4604
|
+
false,
|
|
4605
|
+
async (keyedResults) => {
|
|
4606
|
+
let results = await singleFetchLoaderNavigationStrategy(
|
|
4607
|
+
manifest,
|
|
4608
|
+
routeModules,
|
|
4609
|
+
ssr,
|
|
4610
|
+
getRouter(),
|
|
4611
|
+
request,
|
|
4612
|
+
matches,
|
|
4613
|
+
basename
|
|
4614
|
+
);
|
|
4615
|
+
Object.assign(keyedResults, results);
|
|
4616
|
+
},
|
|
4617
|
+
middlewareErrorHandler
|
|
4618
|
+
);
|
|
4396
4619
|
};
|
|
4397
4620
|
}
|
|
4398
|
-
async function singleFetchActionStrategy(request, matches) {
|
|
4621
|
+
async function singleFetchActionStrategy(request, matches, basename) {
|
|
4399
4622
|
let actionMatch = matches.find((m) => m.shouldLoad);
|
|
4400
4623
|
invariant2(actionMatch, "No action match found");
|
|
4401
4624
|
let actionStatus = void 0;
|
|
4402
4625
|
let result = await actionMatch.resolve(async (handler) => {
|
|
4403
4626
|
let result2 = await handler(async () => {
|
|
4404
|
-
let url = singleFetchUrl(request.url);
|
|
4627
|
+
let url = singleFetchUrl(request.url, basename);
|
|
4405
4628
|
let init = await createRequestInit(request);
|
|
4406
4629
|
let { data: data2, status } = await fetchAndDecode(url, init);
|
|
4407
4630
|
actionStatus = status;
|
|
@@ -4422,13 +4645,46 @@ async function singleFetchActionStrategy(request, matches) {
|
|
|
4422
4645
|
}
|
|
4423
4646
|
};
|
|
4424
4647
|
}
|
|
4425
|
-
async function
|
|
4648
|
+
async function nonSsrStrategy(manifest, request, matches, basename) {
|
|
4649
|
+
let matchesToLoad = matches.filter((m) => m.shouldLoad);
|
|
4650
|
+
let url = stripIndexParam(singleFetchUrl(request.url, basename));
|
|
4651
|
+
let init = await createRequestInit(request);
|
|
4652
|
+
let results = {};
|
|
4653
|
+
await Promise.all(
|
|
4654
|
+
matchesToLoad.map(
|
|
4655
|
+
(m) => m.resolve(async (handler) => {
|
|
4656
|
+
try {
|
|
4657
|
+
let result = manifest.routes[m.route.id]?.hasClientLoader ? await fetchSingleLoader(handler, url, init, m.route.id) : await handler();
|
|
4658
|
+
results[m.route.id] = { type: "data", result };
|
|
4659
|
+
} catch (e) {
|
|
4660
|
+
results[m.route.id] = { type: "error", result: e };
|
|
4661
|
+
}
|
|
4662
|
+
})
|
|
4663
|
+
)
|
|
4664
|
+
);
|
|
4665
|
+
return results;
|
|
4666
|
+
}
|
|
4667
|
+
function isOptedOut(manifestRoute, routeModule, match, router2) {
|
|
4668
|
+
return match.route.id in router2.state.loaderData && manifestRoute && manifestRoute.hasLoader && routeModule && routeModule.shouldRevalidate;
|
|
4669
|
+
}
|
|
4670
|
+
function getLowestLoadingIndex(manifest, routeModules, router2, matches) {
|
|
4671
|
+
let tailIdx = [...matches].reverse().findIndex(
|
|
4672
|
+
(m) => m.shouldLoad || !isOptedOut(
|
|
4673
|
+
manifest.routes[m.route.id],
|
|
4674
|
+
routeModules[m.route.id],
|
|
4675
|
+
m,
|
|
4676
|
+
router2
|
|
4677
|
+
)
|
|
4678
|
+
);
|
|
4679
|
+
return tailIdx < 0 ? 0 : matches.length - 1 - tailIdx;
|
|
4680
|
+
}
|
|
4681
|
+
async function singleFetchLoaderNavigationStrategy(manifest, routeModules, ssr, router2, request, matches, basename) {
|
|
4426
4682
|
let routesParams = /* @__PURE__ */ new Set();
|
|
4427
4683
|
let foundOptOutRoute = false;
|
|
4428
4684
|
let routeDfds = matches.map(() => createDeferred2());
|
|
4429
4685
|
let routesLoadedPromise = Promise.all(routeDfds.map((d) => d.promise));
|
|
4430
4686
|
let singleFetchDfd = createDeferred2();
|
|
4431
|
-
let url = stripIndexParam(singleFetchUrl(request.url));
|
|
4687
|
+
let url = stripIndexParam(singleFetchUrl(request.url, basename));
|
|
4432
4688
|
let init = await createRequestInit(request);
|
|
4433
4689
|
let results = {};
|
|
4434
4690
|
let resolvePromise = Promise.all(
|
|
@@ -4440,7 +4696,7 @@ async function singleFetchLoaderNavigationStrategy(manifest, routeModules, ssr,
|
|
|
4440
4696
|
if (!router2.state.initialized) {
|
|
4441
4697
|
return;
|
|
4442
4698
|
}
|
|
4443
|
-
if (
|
|
4699
|
+
if (isOptedOut(manifestRoute, routeModules[m.route.id], m, router2)) {
|
|
4444
4700
|
foundOptOutRoute = true;
|
|
4445
4701
|
return;
|
|
4446
4702
|
}
|
|
@@ -4503,11 +4759,11 @@ async function singleFetchLoaderNavigationStrategy(manifest, routeModules, ssr,
|
|
|
4503
4759
|
await resolvePromise;
|
|
4504
4760
|
return results;
|
|
4505
4761
|
}
|
|
4506
|
-
async function singleFetchLoaderFetcherStrategy(request, matches) {
|
|
4762
|
+
async function singleFetchLoaderFetcherStrategy(request, matches, basename) {
|
|
4507
4763
|
let fetcherMatch = matches.find((m) => m.shouldLoad);
|
|
4508
4764
|
invariant2(fetcherMatch, "No fetcher match found");
|
|
4509
4765
|
let result = await fetcherMatch.resolve(async (handler) => {
|
|
4510
|
-
let url = stripIndexParam(singleFetchUrl(request.url));
|
|
4766
|
+
let url = stripIndexParam(singleFetchUrl(request.url, basename));
|
|
4511
4767
|
let init = await createRequestInit(request);
|
|
4512
4768
|
return fetchSingleLoader(handler, url, init, fetcherMatch.route.id);
|
|
4513
4769
|
});
|
|
@@ -4535,7 +4791,7 @@ function stripIndexParam(url) {
|
|
|
4535
4791
|
}
|
|
4536
4792
|
return url;
|
|
4537
4793
|
}
|
|
4538
|
-
function singleFetchUrl(reqUrl) {
|
|
4794
|
+
function singleFetchUrl(reqUrl, basename) {
|
|
4539
4795
|
let url = typeof reqUrl === "string" ? new URL(
|
|
4540
4796
|
reqUrl,
|
|
4541
4797
|
// This can be called during the SSR flow via PrefetchPageLinksImpl so
|
|
@@ -4544,6 +4800,8 @@ function singleFetchUrl(reqUrl) {
|
|
|
4544
4800
|
) : reqUrl;
|
|
4545
4801
|
if (url.pathname === "/") {
|
|
4546
4802
|
url.pathname = "_root.data";
|
|
4803
|
+
} else if (basename && stripBasename(url.pathname, basename) === "/") {
|
|
4804
|
+
url.pathname = `${basename.replace(/\/$/, "")}/_root.data`;
|
|
4547
4805
|
} else {
|
|
4548
4806
|
url.pathname = `${url.pathname.replace(/\/$/, "")}.data`;
|
|
4549
4807
|
}
|
|
@@ -4895,6 +5153,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
4895
5153
|
Object.assign(dataRoute, {
|
|
4896
5154
|
...dataRoute,
|
|
4897
5155
|
...getRouteComponents(route, routeModule, isSpaMode),
|
|
5156
|
+
unstable_middleware: routeModule.unstable_clientMiddleware,
|
|
4898
5157
|
handle: routeModule.handle,
|
|
4899
5158
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
4900
5159
|
routeModule,
|
|
@@ -4908,7 +5167,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
4908
5167
|
let hasInitialError = initialState && initialState.errors && route.id in initialState.errors;
|
|
4909
5168
|
let initialError = hasInitialError ? initialState?.errors?.[route.id] : void 0;
|
|
4910
5169
|
let isHydrationRequest = needsRevalidation == null && (routeModule.clientLoader?.hydrate === true || !route.hasLoader);
|
|
4911
|
-
dataRoute.loader = async ({ request, params }, singleFetch) => {
|
|
5170
|
+
dataRoute.loader = async ({ request, params, context }, singleFetch) => {
|
|
4912
5171
|
try {
|
|
4913
5172
|
let result = await prefetchStylesAndCallHandler(async () => {
|
|
4914
5173
|
invariant2(
|
|
@@ -4921,6 +5180,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
4921
5180
|
return routeModule.clientLoader({
|
|
4922
5181
|
request,
|
|
4923
5182
|
params,
|
|
5183
|
+
context,
|
|
4924
5184
|
async serverLoader() {
|
|
4925
5185
|
preventInvalidServerHandlerCall("loader", route);
|
|
4926
5186
|
if (isHydrationRequest) {
|
|
@@ -4945,7 +5205,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
4945
5205
|
routeModule,
|
|
4946
5206
|
isSpaMode
|
|
4947
5207
|
);
|
|
4948
|
-
dataRoute.action = ({ request, params }, singleFetch) => {
|
|
5208
|
+
dataRoute.action = ({ request, params, context }, singleFetch) => {
|
|
4949
5209
|
return prefetchStylesAndCallHandler(async () => {
|
|
4950
5210
|
invariant2(
|
|
4951
5211
|
routeModule,
|
|
@@ -4960,6 +5220,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
4960
5220
|
return routeModule.clientAction({
|
|
4961
5221
|
request,
|
|
4962
5222
|
params,
|
|
5223
|
+
context,
|
|
4963
5224
|
async serverAction() {
|
|
4964
5225
|
preventInvalidServerHandlerCall("action", route);
|
|
4965
5226
|
return fetchServerAction(singleFetch);
|
|
@@ -4969,7 +5230,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
4969
5230
|
};
|
|
4970
5231
|
} else {
|
|
4971
5232
|
if (!route.hasClientLoader) {
|
|
4972
|
-
dataRoute.loader = (
|
|
5233
|
+
dataRoute.loader = (_, singleFetch) => prefetchStylesAndCallHandler(() => {
|
|
4973
5234
|
return fetchServerLoader(singleFetch);
|
|
4974
5235
|
});
|
|
4975
5236
|
} else if (route.clientLoaderModule) {
|
|
@@ -4990,7 +5251,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
4990
5251
|
};
|
|
4991
5252
|
}
|
|
4992
5253
|
if (!route.hasClientAction) {
|
|
4993
|
-
dataRoute.action = (
|
|
5254
|
+
dataRoute.action = (_, singleFetch) => prefetchStylesAndCallHandler(() => {
|
|
4994
5255
|
if (isSpaMode) {
|
|
4995
5256
|
throw noActionDefinedError("clientAction", route.id);
|
|
4996
5257
|
}
|
|
@@ -5048,6 +5309,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
|
|
|
5048
5309
|
return {
|
|
5049
5310
|
...lazyRoute.loader ? { loader: lazyRoute.loader } : {},
|
|
5050
5311
|
...lazyRoute.action ? { action: lazyRoute.action } : {},
|
|
5312
|
+
unstable_middleware: mod.unstable_clientMiddleware,
|
|
5051
5313
|
hasErrorBoundary: lazyRoute.hasErrorBoundary,
|
|
5052
5314
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
5053
5315
|
lazyRoute,
|
|
@@ -5120,6 +5382,7 @@ async function loadRouteModuleWithBlockingLinks(route, routeModules) {
|
|
|
5120
5382
|
return {
|
|
5121
5383
|
Component: getRouteModuleComponent(routeModule),
|
|
5122
5384
|
ErrorBoundary: routeModule.ErrorBoundary,
|
|
5385
|
+
unstable_clientMiddleware: routeModule.unstable_clientMiddleware,
|
|
5123
5386
|
clientAction: routeModule.clientAction,
|
|
5124
5387
|
clientLoader: routeModule.clientLoader,
|
|
5125
5388
|
handle: routeModule.handle,
|
|
@@ -5175,12 +5438,13 @@ function getPatchRoutesOnNavigationFunction(manifest, routeModules, ssr, isSpaMo
|
|
|
5175
5438
|
if (!isFogOfWarEnabled(ssr)) {
|
|
5176
5439
|
return void 0;
|
|
5177
5440
|
}
|
|
5178
|
-
return async ({ path, patch, signal }) => {
|
|
5441
|
+
return async ({ path, patch, signal, fetcherKey }) => {
|
|
5179
5442
|
if (discoveredPaths.has(path)) {
|
|
5180
5443
|
return;
|
|
5181
5444
|
}
|
|
5182
5445
|
await fetchAndApplyManifestPatches(
|
|
5183
5446
|
[path],
|
|
5447
|
+
fetcherKey ? window.location.href : path,
|
|
5184
5448
|
manifest,
|
|
5185
5449
|
routeModules,
|
|
5186
5450
|
ssr,
|
|
@@ -5221,6 +5485,7 @@ function useFogOFWarDiscovery(router2, manifest, routeModules, ssr, isSpaMode) {
|
|
|
5221
5485
|
try {
|
|
5222
5486
|
await fetchAndApplyManifestPatches(
|
|
5223
5487
|
lazyPaths,
|
|
5488
|
+
null,
|
|
5224
5489
|
manifest,
|
|
5225
5490
|
routeModules,
|
|
5226
5491
|
ssr,
|
|
@@ -5244,7 +5509,8 @@ function useFogOFWarDiscovery(router2, manifest, routeModules, ssr, isSpaMode) {
|
|
|
5244
5509
|
return () => observer.disconnect();
|
|
5245
5510
|
}, [ssr, isSpaMode, manifest, routeModules, router2]);
|
|
5246
5511
|
}
|
|
5247
|
-
|
|
5512
|
+
var MANIFEST_VERSION_STORAGE_KEY = "react-router-manifest-version";
|
|
5513
|
+
async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, patchRoutes, signal) {
|
|
5248
5514
|
let manifestPath = `${basename != null ? basename : "/"}/__manifest`.replace(
|
|
5249
5515
|
/\/+/g,
|
|
5250
5516
|
"/"
|
|
@@ -5261,9 +5527,26 @@ async function fetchAndApplyManifestPatches(paths, manifest, routeModules, ssr,
|
|
|
5261
5527
|
let res = await fetch(url, { signal });
|
|
5262
5528
|
if (!res.ok) {
|
|
5263
5529
|
throw new Error(`${res.status} ${res.statusText}`);
|
|
5530
|
+
} else if (res.status === 204 && res.headers.has("X-Remix-Reload-Document")) {
|
|
5531
|
+
if (!errorReloadPath) {
|
|
5532
|
+
console.warn(
|
|
5533
|
+
"Detected a manifest version mismatch during eager route discovery. The next navigation/fetch to an undiscovered route will result in a new document navigation to sync up with the latest manifest."
|
|
5534
|
+
);
|
|
5535
|
+
return;
|
|
5536
|
+
}
|
|
5537
|
+
if (sessionStorage.getItem(MANIFEST_VERSION_STORAGE_KEY) === manifest.version) {
|
|
5538
|
+
console.error(
|
|
5539
|
+
"Unable to discover routes due to manifest version mismatch."
|
|
5540
|
+
);
|
|
5541
|
+
return;
|
|
5542
|
+
}
|
|
5543
|
+
sessionStorage.setItem(MANIFEST_VERSION_STORAGE_KEY, manifest.version);
|
|
5544
|
+
window.location.href = errorReloadPath;
|
|
5545
|
+
throw new Error("Detected manifest version mismatch, reloading...");
|
|
5264
5546
|
} else if (res.status >= 400) {
|
|
5265
5547
|
throw new Error(await res.text());
|
|
5266
5548
|
}
|
|
5549
|
+
sessionStorage.removeItem(MANIFEST_VERSION_STORAGE_KEY);
|
|
5267
5550
|
serverPatches = await res.json();
|
|
5268
5551
|
} catch (e) {
|
|
5269
5552
|
if (signal?.aborted) return;
|
|
@@ -5519,7 +5802,9 @@ function initSsrInfo() {
|
|
|
5519
5802
|
};
|
|
5520
5803
|
}
|
|
5521
5804
|
}
|
|
5522
|
-
function createHydratedRouter(
|
|
5805
|
+
function createHydratedRouter({
|
|
5806
|
+
unstable_getContext
|
|
5807
|
+
}) {
|
|
5523
5808
|
initSsrInfo();
|
|
5524
5809
|
if (!ssrInfo) {
|
|
5525
5810
|
throw new Error(
|
|
@@ -5589,12 +5874,17 @@ function createHydratedRouter() {
|
|
|
5589
5874
|
routes,
|
|
5590
5875
|
history: createBrowserHistory(),
|
|
5591
5876
|
basename: ssrInfo.context.basename,
|
|
5877
|
+
unstable_getContext,
|
|
5592
5878
|
hydrationData,
|
|
5593
5879
|
mapRouteProperties,
|
|
5880
|
+
future: {
|
|
5881
|
+
unstable_middleware: ssrInfo.context.future.unstable_middleware
|
|
5882
|
+
},
|
|
5594
5883
|
dataStrategy: getSingleFetchDataStrategy(
|
|
5595
5884
|
ssrInfo.manifest,
|
|
5596
5885
|
ssrInfo.routeModules,
|
|
5597
5886
|
ssrInfo.context.ssr,
|
|
5887
|
+
ssrInfo.context.basename,
|
|
5598
5888
|
() => router2
|
|
5599
5889
|
),
|
|
5600
5890
|
patchRoutesOnNavigation: getPatchRoutesOnNavigationFunction(
|
|
@@ -5615,9 +5905,11 @@ function createHydratedRouter() {
|
|
|
5615
5905
|
window.__reactRouterDataRouter = router2;
|
|
5616
5906
|
return router2;
|
|
5617
5907
|
}
|
|
5618
|
-
function HydratedRouter() {
|
|
5908
|
+
function HydratedRouter(props) {
|
|
5619
5909
|
if (!router) {
|
|
5620
|
-
router = createHydratedRouter(
|
|
5910
|
+
router = createHydratedRouter({
|
|
5911
|
+
unstable_getContext: props.unstable_getContext
|
|
5912
|
+
});
|
|
5621
5913
|
}
|
|
5622
5914
|
let [criticalCss, setCriticalCss] = React11.useState(
|
|
5623
5915
|
process.env.NODE_ENV === "development" ? ssrInfo?.context.criticalCss : void 0
|