react-router 0.0.0-experimental-beaa4f52a → 0.0.0-experimental-df0f1dfda
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/dist/development/{chunk-3SBCR7VW.mjs → chunk-O5WSUTKP.mjs} +467 -758
- package/dist/development/data-CQbyyGzl.d.mts +11 -0
- package/dist/development/data-CQbyyGzl.d.ts +11 -0
- package/dist/development/dom-export.d.mts +3 -13
- package/dist/development/dom-export.d.ts +3 -13
- package/dist/development/dom-export.js +193 -262
- package/dist/development/dom-export.mjs +6 -9
- package/dist/development/{fog-of-war-CrM4EOZM.d.ts → fog-of-war-D3ny56dR.d.mts} +11 -87
- package/dist/{production/fog-of-war-CrM4EOZM.d.ts → development/fog-of-war-L5G-Cw9x.d.ts} +11 -87
- package/dist/development/index.d.mts +11 -7
- package/dist/development/index.d.ts +11 -7
- package/dist/development/index.js +467 -758
- package/dist/development/index.mjs +2 -2
- package/dist/development/lib/types/route-module.d.mts +5 -13
- package/dist/development/lib/types/route-module.d.ts +5 -13
- package/dist/development/lib/types/route-module.js +1 -1
- package/dist/development/lib/types/route-module.mjs +1 -1
- package/dist/development/{route-data-C9zMg-qq.d.ts → route-data-Cq_b5feC.d.mts} +17 -54
- package/dist/{production/route-data-C9zMg-qq.d.mts → development/route-data-Cq_b5feC.d.ts} +17 -54
- package/dist/production/{chunk-DRRQRV77.mjs → chunk-F7U65DMX.mjs} +467 -758
- package/dist/production/data-CQbyyGzl.d.mts +11 -0
- package/dist/production/data-CQbyyGzl.d.ts +11 -0
- package/dist/production/dom-export.d.mts +3 -13
- package/dist/production/dom-export.d.ts +3 -13
- package/dist/production/dom-export.js +193 -262
- package/dist/production/dom-export.mjs +6 -9
- package/dist/production/{fog-of-war-CYAe8qUt.d.mts → fog-of-war-D3ny56dR.d.mts} +11 -87
- package/dist/{development/fog-of-war-CYAe8qUt.d.mts → production/fog-of-war-L5G-Cw9x.d.ts} +11 -87
- package/dist/production/index.d.mts +11 -7
- package/dist/production/index.d.ts +11 -7
- package/dist/production/index.js +467 -758
- package/dist/production/index.mjs +2 -2
- package/dist/production/lib/types/route-module.d.mts +5 -13
- package/dist/production/lib/types/route-module.d.ts +5 -13
- package/dist/production/lib/types/route-module.js +1 -1
- package/dist/production/lib/types/route-module.mjs +1 -1
- package/dist/production/{route-data-C9zMg-qq.d.ts → route-data-Cq_b5feC.d.mts} +17 -54
- package/dist/{development/route-data-C9zMg-qq.d.mts → production/route-data-Cq_b5feC.d.ts} +17 -54
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v0.0.0-experimental-
|
|
2
|
+
* react-router v0.0.0-experimental-df0f1dfda
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -907,7 +907,6 @@ function createRouter(init) {
|
|
|
907
907
|
);
|
|
908
908
|
let inFlightDataRoutes;
|
|
909
909
|
let basename = init.basename || "/";
|
|
910
|
-
let routerContext = typeof init.context !== "undefined" ? init.context : {};
|
|
911
910
|
let dataStrategyImpl = init.dataStrategy || defaultDataStrategy;
|
|
912
911
|
let patchRoutesOnNavigationImpl = init.patchRoutesOnNavigation;
|
|
913
912
|
let future = {
|
|
@@ -920,6 +919,7 @@ function createRouter(init) {
|
|
|
920
919
|
let getScrollPosition = null;
|
|
921
920
|
let initialScrollRestored = init.hydrationData != null;
|
|
922
921
|
let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
|
|
922
|
+
let initialMatchesIsFOW = false;
|
|
923
923
|
let initialErrors = null;
|
|
924
924
|
if (initialMatches == null && !patchRoutesOnNavigationImpl) {
|
|
925
925
|
let error = getInternalRouterError(404, {
|
|
@@ -949,6 +949,7 @@ function createRouter(init) {
|
|
|
949
949
|
init.history.location.pathname
|
|
950
950
|
);
|
|
951
951
|
if (fogOfWar.active && fogOfWar.matches) {
|
|
952
|
+
initialMatchesIsFOW = true;
|
|
952
953
|
initialMatches = fogOfWar.matches;
|
|
953
954
|
}
|
|
954
955
|
} else if (initialMatches.some((m) => m.route.lazy)) {
|
|
@@ -1314,7 +1315,10 @@ function createRouter(init) {
|
|
|
1314
1315
|
pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
|
|
1315
1316
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
1316
1317
|
let loadingNavigation = opts && opts.overrideNavigation;
|
|
1317
|
-
let matches =
|
|
1318
|
+
let matches = opts?.initialHydration && state.matches && state.matches.length > 0 && !initialMatchesIsFOW ? (
|
|
1319
|
+
// `matchRoutes()` has already been called if we're in here via `router.initialize()`
|
|
1320
|
+
state.matches
|
|
1321
|
+
) : matchRoutes(routesToUse, location, basename);
|
|
1318
1322
|
let flushSync = (opts && opts.flushSync) === true;
|
|
1319
1323
|
let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
|
|
1320
1324
|
if (fogOfWar.active && fogOfWar.matches) {
|
|
@@ -1348,7 +1352,6 @@ function createRouter(init) {
|
|
|
1348
1352
|
pendingNavigationController.signal,
|
|
1349
1353
|
opts && opts.submission
|
|
1350
1354
|
);
|
|
1351
|
-
let scopedContext = { ...routerContext };
|
|
1352
1355
|
let pendingActionResult;
|
|
1353
1356
|
if (opts && opts.pendingError) {
|
|
1354
1357
|
pendingActionResult = [
|
|
@@ -1361,7 +1364,6 @@ function createRouter(init) {
|
|
|
1361
1364
|
location,
|
|
1362
1365
|
opts.submission,
|
|
1363
1366
|
matches,
|
|
1364
|
-
scopedContext,
|
|
1365
1367
|
fogOfWar.active,
|
|
1366
1368
|
{ replace: opts.replace, flushSync }
|
|
1367
1369
|
);
|
|
@@ -1402,7 +1404,6 @@ function createRouter(init) {
|
|
|
1402
1404
|
request,
|
|
1403
1405
|
location,
|
|
1404
1406
|
matches,
|
|
1405
|
-
scopedContext,
|
|
1406
1407
|
fogOfWar.active,
|
|
1407
1408
|
loadingNavigation,
|
|
1408
1409
|
opts && opts.submission,
|
|
@@ -1423,7 +1424,7 @@ function createRouter(init) {
|
|
|
1423
1424
|
errors
|
|
1424
1425
|
});
|
|
1425
1426
|
}
|
|
1426
|
-
async function handleAction(request, location, submission, matches,
|
|
1427
|
+
async function handleAction(request, location, submission, matches, isFogOfWar, opts = {}) {
|
|
1427
1428
|
interruptActiveLoads();
|
|
1428
1429
|
let navigation = getSubmittingNavigation(location, submission);
|
|
1429
1430
|
updateState({ navigation }, { flushSync: opts.flushSync === true });
|
|
@@ -1477,23 +1478,15 @@ function createRouter(init) {
|
|
|
1477
1478
|
})
|
|
1478
1479
|
};
|
|
1479
1480
|
} else {
|
|
1480
|
-
let results = await
|
|
1481
|
+
let results = await callDataStrategy(
|
|
1481
1482
|
"action",
|
|
1483
|
+
state,
|
|
1482
1484
|
request,
|
|
1483
1485
|
[actionMatch],
|
|
1484
1486
|
matches,
|
|
1485
|
-
scopedContext,
|
|
1486
1487
|
null
|
|
1487
1488
|
);
|
|
1488
1489
|
result = results[actionMatch.route.id];
|
|
1489
|
-
if (!result) {
|
|
1490
|
-
for (let match of matches) {
|
|
1491
|
-
if (results[match.route.id]) {
|
|
1492
|
-
result = results[match.route.id];
|
|
1493
|
-
break;
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
1490
|
if (request.signal.aborted) {
|
|
1498
1491
|
return { shortCircuited: true };
|
|
1499
1492
|
}
|
|
@@ -1531,7 +1524,7 @@ function createRouter(init) {
|
|
|
1531
1524
|
pendingActionResult: [actionMatch.route.id, result]
|
|
1532
1525
|
};
|
|
1533
1526
|
}
|
|
1534
|
-
async function handleLoaders(request, location, matches,
|
|
1527
|
+
async function handleLoaders(request, location, matches, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync, pendingActionResult) {
|
|
1535
1528
|
let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
|
|
1536
1529
|
let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
|
|
1537
1530
|
let shouldUpdateNavigationState = !isUninterruptedRevalidation && !initialHydration;
|
|
@@ -1641,11 +1634,11 @@ function createRouter(init) {
|
|
|
1641
1634
|
);
|
|
1642
1635
|
}
|
|
1643
1636
|
let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
|
1637
|
+
state,
|
|
1644
1638
|
matches,
|
|
1645
1639
|
matchesToLoad,
|
|
1646
1640
|
revalidatingFetchers,
|
|
1647
|
-
request
|
|
1648
|
-
scopedContext
|
|
1641
|
+
request
|
|
1649
1642
|
);
|
|
1650
1643
|
if (request.signal.aborted) {
|
|
1651
1644
|
return { shortCircuited: true };
|
|
@@ -1753,7 +1746,6 @@ function createRouter(init) {
|
|
|
1753
1746
|
return;
|
|
1754
1747
|
}
|
|
1755
1748
|
let match = getTargetMatch(matches, path);
|
|
1756
|
-
let scopedContext = { ...routerContext };
|
|
1757
1749
|
let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1758
1750
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
1759
1751
|
await handleFetcherAction(
|
|
@@ -1762,7 +1754,6 @@ function createRouter(init) {
|
|
|
1762
1754
|
path,
|
|
1763
1755
|
match,
|
|
1764
1756
|
matches,
|
|
1765
|
-
scopedContext,
|
|
1766
1757
|
fogOfWar.active,
|
|
1767
1758
|
flushSync,
|
|
1768
1759
|
preventScrollReset,
|
|
@@ -1777,14 +1768,13 @@ function createRouter(init) {
|
|
|
1777
1768
|
path,
|
|
1778
1769
|
match,
|
|
1779
1770
|
matches,
|
|
1780
|
-
scopedContext,
|
|
1781
1771
|
fogOfWar.active,
|
|
1782
1772
|
flushSync,
|
|
1783
1773
|
preventScrollReset,
|
|
1784
1774
|
submission
|
|
1785
1775
|
);
|
|
1786
1776
|
}
|
|
1787
|
-
async function handleFetcherAction(key, routeId, path, match, requestMatches,
|
|
1777
|
+
async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
1788
1778
|
interruptActiveLoads();
|
|
1789
1779
|
fetchLoadMatches.delete(key);
|
|
1790
1780
|
function detectAndHandle405Error(m) {
|
|
@@ -1842,12 +1832,12 @@ function createRouter(init) {
|
|
|
1842
1832
|
}
|
|
1843
1833
|
fetchControllers.set(key, abortController);
|
|
1844
1834
|
let originatingLoadId = incrementingLoadId;
|
|
1845
|
-
let actionResults = await
|
|
1835
|
+
let actionResults = await callDataStrategy(
|
|
1846
1836
|
"action",
|
|
1837
|
+
state,
|
|
1847
1838
|
fetchRequest,
|
|
1848
1839
|
[match],
|
|
1849
1840
|
requestMatches,
|
|
1850
|
-
scopedContext,
|
|
1851
1841
|
key
|
|
1852
1842
|
);
|
|
1853
1843
|
let actionResult = actionResults[match.route.id];
|
|
@@ -1931,11 +1921,11 @@ function createRouter(init) {
|
|
|
1931
1921
|
abortPendingFetchRevalidations
|
|
1932
1922
|
);
|
|
1933
1923
|
let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
|
1924
|
+
state,
|
|
1934
1925
|
matches,
|
|
1935
1926
|
matchesToLoad,
|
|
1936
1927
|
revalidatingFetchers,
|
|
1937
|
-
revalidationRequest
|
|
1938
|
-
scopedContext
|
|
1928
|
+
revalidationRequest
|
|
1939
1929
|
);
|
|
1940
1930
|
if (abortController.signal.aborted) {
|
|
1941
1931
|
return;
|
|
@@ -2002,7 +1992,7 @@ function createRouter(init) {
|
|
|
2002
1992
|
isRevalidationRequired = false;
|
|
2003
1993
|
}
|
|
2004
1994
|
}
|
|
2005
|
-
async function handleFetcherLoader(key, routeId, path, match, matches,
|
|
1995
|
+
async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
2006
1996
|
let existingFetcher = state.fetchers.get(key);
|
|
2007
1997
|
updateFetcherState(
|
|
2008
1998
|
key,
|
|
@@ -2044,12 +2034,12 @@ function createRouter(init) {
|
|
|
2044
2034
|
}
|
|
2045
2035
|
fetchControllers.set(key, abortController);
|
|
2046
2036
|
let originatingLoadId = incrementingLoadId;
|
|
2047
|
-
let results = await
|
|
2037
|
+
let results = await callDataStrategy(
|
|
2048
2038
|
"loader",
|
|
2039
|
+
state,
|
|
2049
2040
|
fetchRequest,
|
|
2050
2041
|
[match],
|
|
2051
2042
|
matches,
|
|
2052
|
-
scopedContext,
|
|
2053
2043
|
key
|
|
2054
2044
|
);
|
|
2055
2045
|
let result = results[match.route.id];
|
|
@@ -2151,20 +2141,20 @@ function createRouter(init) {
|
|
|
2151
2141
|
});
|
|
2152
2142
|
}
|
|
2153
2143
|
}
|
|
2154
|
-
async function
|
|
2144
|
+
async function callDataStrategy(type, state2, request, matchesToLoad, matches, fetcherKey) {
|
|
2155
2145
|
let results;
|
|
2156
2146
|
let dataResults = {};
|
|
2157
2147
|
try {
|
|
2158
2148
|
results = await callDataStrategyImpl(
|
|
2159
2149
|
dataStrategyImpl,
|
|
2160
2150
|
type,
|
|
2151
|
+
state2,
|
|
2161
2152
|
request,
|
|
2162
2153
|
matchesToLoad,
|
|
2163
2154
|
matches,
|
|
2164
2155
|
fetcherKey,
|
|
2165
2156
|
manifest,
|
|
2166
|
-
mapRouteProperties2
|
|
2167
|
-
scopedContext
|
|
2157
|
+
mapRouteProperties2
|
|
2168
2158
|
);
|
|
2169
2159
|
} catch (e) {
|
|
2170
2160
|
matchesToLoad.forEach((m) => {
|
|
@@ -2196,24 +2186,24 @@ function createRouter(init) {
|
|
|
2196
2186
|
}
|
|
2197
2187
|
return dataResults;
|
|
2198
2188
|
}
|
|
2199
|
-
async function callLoadersAndMaybeResolveData(matches, matchesToLoad, fetchersToLoad, request
|
|
2200
|
-
let loaderResultsPromise =
|
|
2189
|
+
async function callLoadersAndMaybeResolveData(state2, matches, matchesToLoad, fetchersToLoad, request) {
|
|
2190
|
+
let loaderResultsPromise = callDataStrategy(
|
|
2201
2191
|
"loader",
|
|
2192
|
+
state2,
|
|
2202
2193
|
request,
|
|
2203
2194
|
matchesToLoad,
|
|
2204
2195
|
matches,
|
|
2205
|
-
scopedContext,
|
|
2206
2196
|
null
|
|
2207
2197
|
);
|
|
2208
2198
|
let fetcherResultsPromise = Promise.all(
|
|
2209
2199
|
fetchersToLoad.map(async (f) => {
|
|
2210
2200
|
if (f.matches && f.match && f.controller) {
|
|
2211
|
-
let results = await
|
|
2201
|
+
let results = await callDataStrategy(
|
|
2212
2202
|
"loader",
|
|
2203
|
+
state2,
|
|
2213
2204
|
createClientSideRequest(init.history, f.path, f.controller.signal),
|
|
2214
2205
|
[f.match],
|
|
2215
2206
|
f.matches,
|
|
2216
|
-
scopedContext,
|
|
2217
2207
|
f.key
|
|
2218
2208
|
);
|
|
2219
2209
|
let result = results[f.match.route.id];
|
|
@@ -2589,21 +2579,17 @@ function createStaticHandler(routes, opts) {
|
|
|
2589
2579
|
);
|
|
2590
2580
|
async function query(request, {
|
|
2591
2581
|
requestContext,
|
|
2592
|
-
filterMatchesToLoad,
|
|
2593
2582
|
skipLoaderErrorBubbling,
|
|
2594
|
-
|
|
2595
|
-
dataStrategy,
|
|
2596
|
-
respond
|
|
2583
|
+
dataStrategy
|
|
2597
2584
|
} = {}) {
|
|
2598
2585
|
let url = new URL(request.url);
|
|
2599
2586
|
let method = request.method;
|
|
2600
2587
|
let location = createLocation("", createPath(url), null, "default");
|
|
2601
2588
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2602
|
-
let staticContext;
|
|
2603
2589
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
2604
2590
|
let error = getInternalRouterError(405, { method });
|
|
2605
2591
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
2606
|
-
|
|
2592
|
+
return {
|
|
2607
2593
|
basename,
|
|
2608
2594
|
location,
|
|
2609
2595
|
matches: methodNotAllowedMatches,
|
|
@@ -2619,7 +2605,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2619
2605
|
} else if (!matches) {
|
|
2620
2606
|
let error = getInternalRouterError(404, { pathname: location.pathname });
|
|
2621
2607
|
let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
2622
|
-
|
|
2608
|
+
return {
|
|
2623
2609
|
basename,
|
|
2624
2610
|
location,
|
|
2625
2611
|
matches: notFoundMatches,
|
|
@@ -2632,118 +2618,25 @@ function createStaticHandler(routes, opts) {
|
|
|
2632
2618
|
loaderHeaders: {},
|
|
2633
2619
|
actionHeaders: {}
|
|
2634
2620
|
};
|
|
2635
|
-
} else if (respond) {
|
|
2636
|
-
try {
|
|
2637
|
-
let tailIdx = [...matches].reverse().findIndex((m) => !filterMatchesToLoad || filterMatchesToLoad(m));
|
|
2638
|
-
let lowestLoadingIdx = tailIdx < 0 ? 0 : matches.length - 1 - tailIdx;
|
|
2639
|
-
let renderedStaticContext;
|
|
2640
|
-
let response = await runMiddlewarePipeline(
|
|
2641
|
-
{
|
|
2642
|
-
request,
|
|
2643
|
-
matches,
|
|
2644
|
-
params: matches[0].params,
|
|
2645
|
-
context: requestContext
|
|
2646
|
-
},
|
|
2647
|
-
lowestLoadingIdx,
|
|
2648
|
-
true,
|
|
2649
|
-
async () => {
|
|
2650
|
-
let result = await callQueryHandlers(
|
|
2651
|
-
request,
|
|
2652
|
-
location,
|
|
2653
|
-
matches,
|
|
2654
|
-
requestContext,
|
|
2655
|
-
dataStrategy || defaultDataStrategyWithoutMiddleware,
|
|
2656
|
-
skipLoaderErrorBubbling === true,
|
|
2657
|
-
null,
|
|
2658
|
-
filterMatchesToLoad || null,
|
|
2659
|
-
skipRevalidation === true
|
|
2660
|
-
);
|
|
2661
|
-
if (isResponse(result)) {
|
|
2662
|
-
return result;
|
|
2663
|
-
}
|
|
2664
|
-
renderedStaticContext = {
|
|
2665
|
-
location,
|
|
2666
|
-
basename,
|
|
2667
|
-
...result
|
|
2668
|
-
};
|
|
2669
|
-
let res = await respond(renderedStaticContext);
|
|
2670
|
-
return res;
|
|
2671
|
-
},
|
|
2672
|
-
async (e) => {
|
|
2673
|
-
if (isResponse(e.error)) {
|
|
2674
|
-
return e.error;
|
|
2675
|
-
}
|
|
2676
|
-
let boundary = findNearestBoundary(matches, e.routeId);
|
|
2677
|
-
let errorContext;
|
|
2678
|
-
if (renderedStaticContext) {
|
|
2679
|
-
if (e.routeId in renderedStaticContext.loaderData) {
|
|
2680
|
-
renderedStaticContext.loaderData[e.routeId] = void 0;
|
|
2681
|
-
}
|
|
2682
|
-
errorContext = getStaticContextFromError(
|
|
2683
|
-
dataRoutes,
|
|
2684
|
-
renderedStaticContext,
|
|
2685
|
-
e.error,
|
|
2686
|
-
boundary.route.id
|
|
2687
|
-
);
|
|
2688
|
-
} else {
|
|
2689
|
-
errorContext = {
|
|
2690
|
-
matches,
|
|
2691
|
-
location,
|
|
2692
|
-
basename,
|
|
2693
|
-
loaderData: {},
|
|
2694
|
-
actionData: null,
|
|
2695
|
-
errors: {
|
|
2696
|
-
[boundary.route.id]: e.error
|
|
2697
|
-
},
|
|
2698
|
-
statusCode: isRouteErrorResponse(e.error) ? e.error.status : 500,
|
|
2699
|
-
actionHeaders: {},
|
|
2700
|
-
loaderHeaders: {}
|
|
2701
|
-
};
|
|
2702
|
-
}
|
|
2703
|
-
let res = await respond(errorContext);
|
|
2704
|
-
return res;
|
|
2705
|
-
}
|
|
2706
|
-
);
|
|
2707
|
-
invariant(isResponse(response), "Expected a response in query()");
|
|
2708
|
-
return response;
|
|
2709
|
-
} catch (e) {
|
|
2710
|
-
if (isResponse(e)) {
|
|
2711
|
-
return e;
|
|
2712
|
-
}
|
|
2713
|
-
throw e;
|
|
2714
|
-
}
|
|
2715
|
-
} else {
|
|
2716
|
-
let result = await callQueryHandlers(
|
|
2717
|
-
request,
|
|
2718
|
-
location,
|
|
2719
|
-
matches,
|
|
2720
|
-
requestContext,
|
|
2721
|
-
dataStrategy || null,
|
|
2722
|
-
skipLoaderErrorBubbling === true,
|
|
2723
|
-
null,
|
|
2724
|
-
filterMatchesToLoad || null,
|
|
2725
|
-
skipRevalidation === true
|
|
2726
|
-
);
|
|
2727
|
-
if (isResponse(result)) {
|
|
2728
|
-
return result;
|
|
2729
|
-
}
|
|
2730
|
-
staticContext = {
|
|
2731
|
-
location,
|
|
2732
|
-
basename,
|
|
2733
|
-
...result
|
|
2734
|
-
};
|
|
2735
2621
|
}
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2622
|
+
let result = await queryImpl(
|
|
2623
|
+
request,
|
|
2624
|
+
location,
|
|
2625
|
+
matches,
|
|
2626
|
+
requestContext,
|
|
2627
|
+
dataStrategy || null,
|
|
2628
|
+
skipLoaderErrorBubbling === true,
|
|
2629
|
+
null
|
|
2630
|
+
);
|
|
2631
|
+
if (isResponse(result)) {
|
|
2632
|
+
return result;
|
|
2739
2633
|
}
|
|
2740
|
-
return
|
|
2634
|
+
return { location, basename, ...result };
|
|
2741
2635
|
}
|
|
2742
2636
|
async function queryRoute(request, {
|
|
2743
2637
|
routeId,
|
|
2744
2638
|
requestContext,
|
|
2745
|
-
dataStrategy
|
|
2746
|
-
respond
|
|
2639
|
+
dataStrategy
|
|
2747
2640
|
} = {}) {
|
|
2748
2641
|
let url = new URL(request.url);
|
|
2749
2642
|
let method = request.method;
|
|
@@ -2763,77 +2656,31 @@ function createStaticHandler(routes, opts) {
|
|
|
2763
2656
|
} else if (!match) {
|
|
2764
2657
|
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
2765
2658
|
}
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
match,
|
|
2785
|
-
null,
|
|
2786
|
-
false
|
|
2787
|
-
);
|
|
2788
|
-
if (isResponse(result)) {
|
|
2789
|
-
return respond(result);
|
|
2790
|
-
}
|
|
2791
|
-
let error = result.errors ? Object.values(result.errors)[0] : void 0;
|
|
2792
|
-
if (error !== void 0) {
|
|
2793
|
-
throw error;
|
|
2794
|
-
}
|
|
2795
|
-
throw new Error("Expected a response from queryRoute");
|
|
2796
|
-
},
|
|
2797
|
-
(e) => {
|
|
2798
|
-
if (isResponse(e.error)) {
|
|
2799
|
-
return respond(e.error);
|
|
2800
|
-
}
|
|
2801
|
-
return new Response(String(e.error), {
|
|
2802
|
-
status: 500,
|
|
2803
|
-
statusText: "Unexpected Server Error"
|
|
2804
|
-
});
|
|
2805
|
-
}
|
|
2806
|
-
);
|
|
2807
|
-
return response;
|
|
2808
|
-
} else {
|
|
2809
|
-
let result = await callQueryHandlers(
|
|
2810
|
-
request,
|
|
2811
|
-
location,
|
|
2812
|
-
matches,
|
|
2813
|
-
requestContext,
|
|
2814
|
-
dataStrategy || null,
|
|
2815
|
-
false,
|
|
2816
|
-
match,
|
|
2817
|
-
null,
|
|
2818
|
-
false
|
|
2819
|
-
);
|
|
2820
|
-
if (isResponse(result)) {
|
|
2821
|
-
return result;
|
|
2822
|
-
}
|
|
2823
|
-
let error = result.errors ? Object.values(result.errors)[0] : void 0;
|
|
2824
|
-
if (error !== void 0) {
|
|
2825
|
-
throw error;
|
|
2826
|
-
}
|
|
2827
|
-
if (result.actionData) {
|
|
2828
|
-
return Object.values(result.actionData)[0];
|
|
2829
|
-
}
|
|
2830
|
-
if (result.loaderData) {
|
|
2831
|
-
return Object.values(result.loaderData)[0];
|
|
2832
|
-
}
|
|
2833
|
-
return void 0;
|
|
2659
|
+
let result = await queryImpl(
|
|
2660
|
+
request,
|
|
2661
|
+
location,
|
|
2662
|
+
matches,
|
|
2663
|
+
requestContext,
|
|
2664
|
+
dataStrategy || null,
|
|
2665
|
+
false,
|
|
2666
|
+
match
|
|
2667
|
+
);
|
|
2668
|
+
if (isResponse(result)) {
|
|
2669
|
+
return result;
|
|
2670
|
+
}
|
|
2671
|
+
let error = result.errors ? Object.values(result.errors)[0] : void 0;
|
|
2672
|
+
if (error !== void 0) {
|
|
2673
|
+
throw error;
|
|
2674
|
+
}
|
|
2675
|
+
if (result.actionData) {
|
|
2676
|
+
return Object.values(result.actionData)[0];
|
|
2834
2677
|
}
|
|
2678
|
+
if (result.loaderData) {
|
|
2679
|
+
return Object.values(result.loaderData)[0];
|
|
2680
|
+
}
|
|
2681
|
+
return void 0;
|
|
2835
2682
|
}
|
|
2836
|
-
async function
|
|
2683
|
+
async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch) {
|
|
2837
2684
|
invariant(
|
|
2838
2685
|
request.signal,
|
|
2839
2686
|
"query()/queryRoute() requests must contain an AbortController signal"
|
|
@@ -2847,9 +2694,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2847
2694
|
requestContext,
|
|
2848
2695
|
dataStrategy,
|
|
2849
2696
|
skipLoaderErrorBubbling,
|
|
2850
|
-
routeMatch != null
|
|
2851
|
-
filterMatchesToLoad,
|
|
2852
|
-
skipRevalidation
|
|
2697
|
+
routeMatch != null
|
|
2853
2698
|
);
|
|
2854
2699
|
return result2;
|
|
2855
2700
|
}
|
|
@@ -2859,8 +2704,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2859
2704
|
requestContext,
|
|
2860
2705
|
dataStrategy,
|
|
2861
2706
|
skipLoaderErrorBubbling,
|
|
2862
|
-
routeMatch
|
|
2863
|
-
filterMatchesToLoad
|
|
2707
|
+
routeMatch
|
|
2864
2708
|
);
|
|
2865
2709
|
return isResponse(result) ? result : {
|
|
2866
2710
|
...result,
|
|
@@ -2880,7 +2724,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2880
2724
|
throw e;
|
|
2881
2725
|
}
|
|
2882
2726
|
}
|
|
2883
|
-
async function submit(request, matches, actionMatch, requestContext, dataStrategy, skipLoaderErrorBubbling, isRouteRequest
|
|
2727
|
+
async function submit(request, matches, actionMatch, requestContext, dataStrategy, skipLoaderErrorBubbling, isRouteRequest) {
|
|
2884
2728
|
let result;
|
|
2885
2729
|
if (!actionMatch.route.action && !actionMatch.route.lazy) {
|
|
2886
2730
|
let error = getInternalRouterError(405, {
|
|
@@ -2896,7 +2740,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2896
2740
|
error
|
|
2897
2741
|
};
|
|
2898
2742
|
} else {
|
|
2899
|
-
let results = await
|
|
2743
|
+
let results = await callDataStrategy(
|
|
2900
2744
|
"action",
|
|
2901
2745
|
request,
|
|
2902
2746
|
[actionMatch],
|
|
@@ -2934,36 +2778,6 @@ function createStaticHandler(routes, opts) {
|
|
|
2934
2778
|
actionHeaders: {}
|
|
2935
2779
|
};
|
|
2936
2780
|
}
|
|
2937
|
-
if (skipRevalidation) {
|
|
2938
|
-
if (isErrorResult(result)) {
|
|
2939
|
-
let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
|
|
2940
|
-
return {
|
|
2941
|
-
matches,
|
|
2942
|
-
loaderData: {},
|
|
2943
|
-
actionData: null,
|
|
2944
|
-
errors: {
|
|
2945
|
-
[boundaryMatch.route.id]: result.error
|
|
2946
|
-
},
|
|
2947
|
-
statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500,
|
|
2948
|
-
loaderHeaders: {},
|
|
2949
|
-
actionHeaders: {
|
|
2950
|
-
...result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
|
2951
|
-
}
|
|
2952
|
-
};
|
|
2953
|
-
} else {
|
|
2954
|
-
return {
|
|
2955
|
-
matches,
|
|
2956
|
-
loaderData: {},
|
|
2957
|
-
actionData: {
|
|
2958
|
-
[actionMatch.route.id]: result.data
|
|
2959
|
-
},
|
|
2960
|
-
errors: null,
|
|
2961
|
-
statusCode: result.statusCode || 200,
|
|
2962
|
-
loaderHeaders: {},
|
|
2963
|
-
actionHeaders: result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
|
2964
|
-
};
|
|
2965
|
-
}
|
|
2966
|
-
}
|
|
2967
2781
|
let loaderRequest = new Request(request.url, {
|
|
2968
2782
|
headers: request.headers,
|
|
2969
2783
|
redirect: request.redirect,
|
|
@@ -2971,18 +2785,17 @@ function createStaticHandler(routes, opts) {
|
|
|
2971
2785
|
});
|
|
2972
2786
|
if (isErrorResult(result)) {
|
|
2973
2787
|
let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
|
|
2974
|
-
let
|
|
2788
|
+
let context2 = await loadRouteData(
|
|
2975
2789
|
loaderRequest,
|
|
2976
2790
|
matches,
|
|
2977
2791
|
requestContext,
|
|
2978
2792
|
dataStrategy,
|
|
2979
2793
|
skipLoaderErrorBubbling,
|
|
2980
2794
|
null,
|
|
2981
|
-
filterMatchesToLoad,
|
|
2982
2795
|
[boundaryMatch.route.id, result]
|
|
2983
2796
|
);
|
|
2984
2797
|
return {
|
|
2985
|
-
...
|
|
2798
|
+
...context2,
|
|
2986
2799
|
statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500,
|
|
2987
2800
|
actionData: null,
|
|
2988
2801
|
actionHeaders: {
|
|
@@ -2990,17 +2803,16 @@ function createStaticHandler(routes, opts) {
|
|
|
2990
2803
|
}
|
|
2991
2804
|
};
|
|
2992
2805
|
}
|
|
2993
|
-
let
|
|
2806
|
+
let context = await loadRouteData(
|
|
2994
2807
|
loaderRequest,
|
|
2995
2808
|
matches,
|
|
2996
2809
|
requestContext,
|
|
2997
2810
|
dataStrategy,
|
|
2998
2811
|
skipLoaderErrorBubbling,
|
|
2999
|
-
null
|
|
3000
|
-
filterMatchesToLoad
|
|
2812
|
+
null
|
|
3001
2813
|
);
|
|
3002
2814
|
return {
|
|
3003
|
-
...
|
|
2815
|
+
...context,
|
|
3004
2816
|
actionData: {
|
|
3005
2817
|
[actionMatch.route.id]: result.data
|
|
3006
2818
|
},
|
|
@@ -3009,7 +2821,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3009
2821
|
actionHeaders: result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
|
3010
2822
|
};
|
|
3011
2823
|
}
|
|
3012
|
-
async function loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch,
|
|
2824
|
+
async function loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, pendingActionResult) {
|
|
3013
2825
|
let isRouteRequest = routeMatch != null;
|
|
3014
2826
|
if (isRouteRequest && !routeMatch?.route.loader && !routeMatch?.route.lazy) {
|
|
3015
2827
|
throw getInternalRouterError(400, {
|
|
@@ -3020,7 +2832,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3020
2832
|
}
|
|
3021
2833
|
let requestMatches = routeMatch ? [routeMatch] : pendingActionResult && isErrorResult(pendingActionResult[1]) ? getLoaderMatchesUntilBoundary(matches, pendingActionResult[0]) : matches;
|
|
3022
2834
|
let matchesToLoad = requestMatches.filter(
|
|
3023
|
-
(m) =>
|
|
2835
|
+
(m) => m.route.loader || m.route.lazy
|
|
3024
2836
|
);
|
|
3025
2837
|
if (matchesToLoad.length === 0) {
|
|
3026
2838
|
return {
|
|
@@ -3037,7 +2849,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3037
2849
|
loaderHeaders: {}
|
|
3038
2850
|
};
|
|
3039
2851
|
}
|
|
3040
|
-
let results = await
|
|
2852
|
+
let results = await callDataStrategy(
|
|
3041
2853
|
"loader",
|
|
3042
2854
|
request,
|
|
3043
2855
|
matchesToLoad,
|
|
@@ -3049,7 +2861,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3049
2861
|
if (request.signal.aborted) {
|
|
3050
2862
|
throwStaticHandlerAbortedError(request, isRouteRequest);
|
|
3051
2863
|
}
|
|
3052
|
-
let
|
|
2864
|
+
let context = processRouteLoaderData(
|
|
3053
2865
|
matches,
|
|
3054
2866
|
results,
|
|
3055
2867
|
pendingActionResult,
|
|
@@ -3061,18 +2873,19 @@ function createStaticHandler(routes, opts) {
|
|
|
3061
2873
|
);
|
|
3062
2874
|
matches.forEach((match) => {
|
|
3063
2875
|
if (!executedLoaders.has(match.route.id)) {
|
|
3064
|
-
|
|
2876
|
+
context.loaderData[match.route.id] = null;
|
|
3065
2877
|
}
|
|
3066
2878
|
});
|
|
3067
2879
|
return {
|
|
3068
|
-
...
|
|
2880
|
+
...context,
|
|
3069
2881
|
matches
|
|
3070
2882
|
};
|
|
3071
2883
|
}
|
|
3072
|
-
async function
|
|
2884
|
+
async function callDataStrategy(type, request, matchesToLoad, matches, isRouteRequest, requestContext, dataStrategy) {
|
|
3073
2885
|
let results = await callDataStrategyImpl(
|
|
3074
2886
|
dataStrategy || defaultDataStrategy,
|
|
3075
2887
|
type,
|
|
2888
|
+
null,
|
|
3076
2889
|
request,
|
|
3077
2890
|
matchesToLoad,
|
|
3078
2891
|
matches,
|
|
@@ -3112,15 +2925,15 @@ function createStaticHandler(routes, opts) {
|
|
|
3112
2925
|
queryRoute
|
|
3113
2926
|
};
|
|
3114
2927
|
}
|
|
3115
|
-
function getStaticContextFromError(routes,
|
|
3116
|
-
let
|
|
3117
|
-
|
|
3118
|
-
...handlerContext,
|
|
2928
|
+
function getStaticContextFromError(routes, context, error) {
|
|
2929
|
+
let newContext = {
|
|
2930
|
+
...context,
|
|
3119
2931
|
statusCode: isRouteErrorResponse(error) ? error.status : 500,
|
|
3120
2932
|
errors: {
|
|
3121
|
-
[
|
|
2933
|
+
[context._deepestRenderedBoundaryId || routes[0].id]: error
|
|
3122
2934
|
}
|
|
3123
2935
|
};
|
|
2936
|
+
return newContext;
|
|
3124
2937
|
}
|
|
3125
2938
|
function throwStaticHandlerAbortedError(request, isRouteRequest) {
|
|
3126
2939
|
if (request.signal.reason !== void 0) {
|
|
@@ -3513,141 +3326,20 @@ async function loadLazyRouteModule(route, mapRouteProperties2, manifest) {
|
|
|
3513
3326
|
lazy: void 0
|
|
3514
3327
|
});
|
|
3515
3328
|
}
|
|
3516
|
-
async function
|
|
3517
|
-
|
|
3518
|
-
|
|
3329
|
+
async function defaultDataStrategy({
|
|
3330
|
+
matches
|
|
3331
|
+
}) {
|
|
3332
|
+
let matchesToLoad = matches.filter((m) => m.shouldLoad);
|
|
3519
3333
|
let results = await Promise.all(matchesToLoad.map((m) => m.resolve()));
|
|
3520
|
-
results.
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
return keyedResults;
|
|
3524
|
-
}
|
|
3525
|
-
async function defaultDataStrategy(args) {
|
|
3526
|
-
let matchesToLoad = args.matches.filter((m) => m.shouldLoad);
|
|
3527
|
-
let lastIndex = args.matches.length - 1;
|
|
3528
|
-
for (let i = lastIndex; i >= 0; i--) {
|
|
3529
|
-
if (args.matches[i].shouldLoad) {
|
|
3530
|
-
lastIndex = i;
|
|
3531
|
-
break;
|
|
3532
|
-
}
|
|
3533
|
-
}
|
|
3534
|
-
let results = await runMiddlewarePipeline(
|
|
3535
|
-
args,
|
|
3536
|
-
lastIndex,
|
|
3537
|
-
false,
|
|
3538
|
-
async (keyedResults) => {
|
|
3539
|
-
let results2 = await Promise.all(matchesToLoad.map((m) => m.resolve()));
|
|
3540
|
-
results2.forEach((result, i) => {
|
|
3541
|
-
keyedResults[matchesToLoad[i].route.id] = result;
|
|
3542
|
-
});
|
|
3543
|
-
},
|
|
3544
|
-
(e, keyedResults) => {
|
|
3545
|
-
Object.assign(keyedResults, {
|
|
3546
|
-
[e.routeId]: { type: "error", result: e.error }
|
|
3547
|
-
});
|
|
3548
|
-
}
|
|
3334
|
+
return results.reduce(
|
|
3335
|
+
(acc, result, i) => Object.assign(acc, { [matchesToLoad[i].route.id]: result }),
|
|
3336
|
+
{}
|
|
3549
3337
|
);
|
|
3550
|
-
return results;
|
|
3551
|
-
}
|
|
3552
|
-
async function runMiddlewarePipeline({
|
|
3553
|
-
request,
|
|
3554
|
-
params,
|
|
3555
|
-
context,
|
|
3556
|
-
matches
|
|
3557
|
-
}, lastIndex, propagateResult, handler, errorHandler) {
|
|
3558
|
-
let middlewareState = {
|
|
3559
|
-
keyedResults: {},
|
|
3560
|
-
propagateResult
|
|
3561
|
-
};
|
|
3562
|
-
try {
|
|
3563
|
-
let result = await callRouteMiddleware(
|
|
3564
|
-
matches.slice(0, lastIndex + 1).flatMap(
|
|
3565
|
-
(m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
|
|
3566
|
-
),
|
|
3567
|
-
0,
|
|
3568
|
-
{ request, params, context },
|
|
3569
|
-
middlewareState,
|
|
3570
|
-
handler
|
|
3571
|
-
);
|
|
3572
|
-
return middlewareState.propagateResult ? result : middlewareState.keyedResults;
|
|
3573
|
-
} catch (e) {
|
|
3574
|
-
if (!(e instanceof MiddlewareError)) {
|
|
3575
|
-
throw e;
|
|
3576
|
-
}
|
|
3577
|
-
if (propagateResult && isResponse(e.error)) {
|
|
3578
|
-
throw e.error;
|
|
3579
|
-
}
|
|
3580
|
-
let result = await errorHandler(e, middlewareState.keyedResults);
|
|
3581
|
-
return middlewareState.propagateResult ? result : middlewareState.keyedResults;
|
|
3582
|
-
}
|
|
3583
3338
|
}
|
|
3584
|
-
|
|
3585
|
-
constructor(routeId, error) {
|
|
3586
|
-
this.routeId = routeId;
|
|
3587
|
-
this.error = error;
|
|
3588
|
-
}
|
|
3589
|
-
};
|
|
3590
|
-
async function callRouteMiddleware(middlewares, idx, args, middlewareState, handler) {
|
|
3591
|
-
let { request } = args;
|
|
3592
|
-
if (request.signal.aborted) {
|
|
3593
|
-
if (request.signal.reason) {
|
|
3594
|
-
throw request.signal.reason;
|
|
3595
|
-
}
|
|
3596
|
-
throw new Error(
|
|
3597
|
-
`Request aborted without an \`AbortSignal.reason\`: ${request.method} ${request.url}`
|
|
3598
|
-
);
|
|
3599
|
-
}
|
|
3600
|
-
let tuple = middlewares[idx];
|
|
3601
|
-
if (!tuple) {
|
|
3602
|
-
let result = await handler(middlewareState.keyedResults);
|
|
3603
|
-
return result;
|
|
3604
|
-
}
|
|
3605
|
-
let [routeId, middleware] = tuple;
|
|
3606
|
-
let nextCalled = false;
|
|
3607
|
-
let next = async () => {
|
|
3608
|
-
if (nextCalled) {
|
|
3609
|
-
throw new Error("You may only call `next()` once per middleware");
|
|
3610
|
-
}
|
|
3611
|
-
nextCalled = true;
|
|
3612
|
-
let result = await callRouteMiddleware(
|
|
3613
|
-
middlewares,
|
|
3614
|
-
idx + 1,
|
|
3615
|
-
args,
|
|
3616
|
-
middlewareState,
|
|
3617
|
-
handler
|
|
3618
|
-
);
|
|
3619
|
-
if (middlewareState.propagateResult) {
|
|
3620
|
-
return result;
|
|
3621
|
-
}
|
|
3622
|
-
};
|
|
3623
|
-
try {
|
|
3624
|
-
let result = await middleware({
|
|
3625
|
-
request: args.request,
|
|
3626
|
-
params: args.params,
|
|
3627
|
-
context: args.context,
|
|
3628
|
-
next
|
|
3629
|
-
});
|
|
3630
|
-
return nextCalled ? result : next();
|
|
3631
|
-
} catch (e) {
|
|
3632
|
-
if (e instanceof MiddlewareError) {
|
|
3633
|
-
throw e;
|
|
3634
|
-
}
|
|
3635
|
-
throw new MiddlewareError(routeId, e);
|
|
3636
|
-
}
|
|
3637
|
-
}
|
|
3638
|
-
async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLoad, matches, fetcherKey, manifest, mapRouteProperties2, scopedContext) {
|
|
3339
|
+
async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matchesToLoad, matches, fetcherKey, manifest, mapRouteProperties2, requestContext) {
|
|
3639
3340
|
let loadRouteDefinitionsPromises = matches.map(
|
|
3640
3341
|
(m) => m.route.lazy ? loadLazyRouteModule(m.route, mapRouteProperties2, manifest) : void 0
|
|
3641
3342
|
);
|
|
3642
|
-
let lazyMiddlewarePromises = matches.map(
|
|
3643
|
-
(m, i) => m.route.lazy && !("middleware" in m.route) ? (
|
|
3644
|
-
// Swallow the error here, let it bubble up from resolve()
|
|
3645
|
-
loadRouteDefinitionsPromises[i].catch((e) => e)
|
|
3646
|
-
) : null
|
|
3647
|
-
).filter((p) => p != null);
|
|
3648
|
-
if (lazyMiddlewarePromises.length > 0) {
|
|
3649
|
-
await Promise.all(lazyMiddlewarePromises);
|
|
3650
|
-
}
|
|
3651
3343
|
let dsMatches = matches.map((match, i) => {
|
|
3652
3344
|
let loadRoutePromise = loadRouteDefinitionsPromises[i];
|
|
3653
3345
|
let shouldLoad = matchesToLoad.some((m) => m.route.id === match.route.id);
|
|
@@ -3661,7 +3353,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
|
|
|
3661
3353
|
match,
|
|
3662
3354
|
loadRoutePromise,
|
|
3663
3355
|
handlerOverride,
|
|
3664
|
-
|
|
3356
|
+
requestContext
|
|
3665
3357
|
) : Promise.resolve({ type: "data" /* data */, result: void 0 });
|
|
3666
3358
|
};
|
|
3667
3359
|
return {
|
|
@@ -3675,7 +3367,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
|
|
|
3675
3367
|
request,
|
|
3676
3368
|
params: matches[0].params,
|
|
3677
3369
|
fetcherKey,
|
|
3678
|
-
context:
|
|
3370
|
+
context: requestContext
|
|
3679
3371
|
});
|
|
3680
3372
|
try {
|
|
3681
3373
|
await Promise.all(loadRouteDefinitionsPromises);
|
|
@@ -3683,7 +3375,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
|
|
|
3683
3375
|
}
|
|
3684
3376
|
return results;
|
|
3685
3377
|
}
|
|
3686
|
-
async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride,
|
|
3378
|
+
async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride, staticContext) {
|
|
3687
3379
|
let result;
|
|
3688
3380
|
let onReject;
|
|
3689
3381
|
let runHandler = (handler) => {
|
|
@@ -3703,7 +3395,7 @@ async function callLoaderOrAction(type, request, match, loadRoutePromise, handle
|
|
|
3703
3395
|
{
|
|
3704
3396
|
request,
|
|
3705
3397
|
params: match.params,
|
|
3706
|
-
context:
|
|
3398
|
+
context: staticContext
|
|
3707
3399
|
},
|
|
3708
3400
|
...ctx !== void 0 ? [ctx] : []
|
|
3709
3401
|
);
|
|
@@ -3810,14 +3502,20 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
|
|
|
3810
3502
|
return {
|
|
3811
3503
|
type: "error" /* error */,
|
|
3812
3504
|
error: result.data,
|
|
3813
|
-
statusCode: result.init?.status
|
|
3505
|
+
statusCode: result.init?.status,
|
|
3506
|
+
headers: result.init?.headers ? new Headers(result.init.headers) : void 0
|
|
3814
3507
|
};
|
|
3815
3508
|
}
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3509
|
+
return {
|
|
3510
|
+
type: "error" /* error */,
|
|
3511
|
+
error: new ErrorResponseImpl(
|
|
3512
|
+
result.init?.status || 500,
|
|
3513
|
+
void 0,
|
|
3514
|
+
result.data
|
|
3515
|
+
),
|
|
3516
|
+
statusCode: isRouteErrorResponse(result) ? result.status : void 0,
|
|
3517
|
+
headers: result.init?.headers ? new Headers(result.init.headers) : void 0
|
|
3518
|
+
};
|
|
3821
3519
|
}
|
|
3822
3520
|
return {
|
|
3823
3521
|
type: "error" /* error */,
|
|
@@ -4554,7 +4252,7 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
|
|
|
4554
4252
|
let segments = pathname.replace(/^\//, "").split("/");
|
|
4555
4253
|
remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
|
|
4556
4254
|
}
|
|
4557
|
-
let matches = matchRoutes(routes, { pathname: remainingPathname });
|
|
4255
|
+
let matches = dataRouterState && dataRouterState.matches && dataRouterState.matches.length > 0 ? dataRouterState.matches : matchRoutes(routes, { pathname: remainingPathname });
|
|
4558
4256
|
if (ENABLE_DEV_WARNINGS) {
|
|
4559
4257
|
warning(
|
|
4560
4258
|
parentRoute || matches != null,
|
|
@@ -5010,7 +4708,6 @@ function mapRouteProperties(route) {
|
|
|
5010
4708
|
function createMemoryRouter(routes, opts) {
|
|
5011
4709
|
return createRouter({
|
|
5012
4710
|
basename: opts?.basename,
|
|
5013
|
-
context: opts?.context,
|
|
5014
4711
|
future: opts?.future,
|
|
5015
4712
|
history: createMemoryHistory({
|
|
5016
4713
|
initialEntries: opts?.initialEntries,
|
|
@@ -5662,7 +5359,7 @@ function getKeyedLinksForMatches(matches, routeModules, manifest) {
|
|
|
5662
5359
|
module?.links?.() || []
|
|
5663
5360
|
];
|
|
5664
5361
|
}).flat(2);
|
|
5665
|
-
let preloads =
|
|
5362
|
+
let preloads = getModuleLinkHrefs(matches, manifest);
|
|
5666
5363
|
return dedupeLinkDescriptors(descriptors, preloads);
|
|
5667
5364
|
}
|
|
5668
5365
|
async function prefetchStyleLinks(route, routeModule) {
|
|
@@ -5786,25 +5483,21 @@ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, loca
|
|
|
5786
5483
|
}
|
|
5787
5484
|
return [];
|
|
5788
5485
|
}
|
|
5789
|
-
function getModuleLinkHrefs(matches,
|
|
5790
|
-
return dedupeHrefs(
|
|
5791
|
-
matches.map((match) => {
|
|
5792
|
-
let route = manifestPatch.routes[match.route.id];
|
|
5793
|
-
if (!route) return [];
|
|
5794
|
-
let hrefs = [route.module];
|
|
5795
|
-
if (route.imports) {
|
|
5796
|
-
hrefs = hrefs.concat(route.imports);
|
|
5797
|
-
}
|
|
5798
|
-
return hrefs;
|
|
5799
|
-
}).flat(1)
|
|
5800
|
-
);
|
|
5801
|
-
}
|
|
5802
|
-
function getCurrentPageModulePreloadHrefs(matches, manifest) {
|
|
5486
|
+
function getModuleLinkHrefs(matches, manifest, { includeHydrateFallback } = {}) {
|
|
5803
5487
|
return dedupeHrefs(
|
|
5804
5488
|
matches.map((match) => {
|
|
5805
5489
|
let route = manifest.routes[match.route.id];
|
|
5806
5490
|
if (!route) return [];
|
|
5807
5491
|
let hrefs = [route.module];
|
|
5492
|
+
if (route.clientActionModule) {
|
|
5493
|
+
hrefs = hrefs.concat(route.clientActionModule);
|
|
5494
|
+
}
|
|
5495
|
+
if (route.clientLoaderModule) {
|
|
5496
|
+
hrefs = hrefs.concat(route.clientLoaderModule);
|
|
5497
|
+
}
|
|
5498
|
+
if (includeHydrateFallback && route.hydrateFallbackModule) {
|
|
5499
|
+
hrefs = hrefs.concat(route.hydrateFallbackModule);
|
|
5500
|
+
}
|
|
5808
5501
|
if (route.imports) {
|
|
5809
5502
|
hrefs = hrefs.concat(route.imports);
|
|
5810
5503
|
}
|
|
@@ -5959,63 +5652,21 @@ function StreamTransfer({
|
|
|
5959
5652
|
)));
|
|
5960
5653
|
}
|
|
5961
5654
|
}
|
|
5962
|
-
function middlewareErrorHandler(e, keyedResults) {
|
|
5963
|
-
Object.assign(keyedResults, {
|
|
5964
|
-
[e.routeId]: { type: "error", result: e.error }
|
|
5965
|
-
});
|
|
5966
|
-
}
|
|
5967
5655
|
function getSingleFetchDataStrategy(manifest, routeModules, getRouter) {
|
|
5968
|
-
return async (
|
|
5969
|
-
let { request, matches, fetcherKey } = args;
|
|
5656
|
+
return async ({ request, matches, fetcherKey }) => {
|
|
5970
5657
|
if (request.method !== "GET") {
|
|
5971
|
-
return
|
|
5972
|
-
args,
|
|
5973
|
-
matches.findIndex((m) => m.shouldLoad),
|
|
5974
|
-
false,
|
|
5975
|
-
async (keyedResults) => {
|
|
5976
|
-
let results = await singleFetchActionStrategy(request, matches);
|
|
5977
|
-
Object.assign(keyedResults, results);
|
|
5978
|
-
},
|
|
5979
|
-
middlewareErrorHandler
|
|
5980
|
-
);
|
|
5658
|
+
return singleFetchActionStrategy(request, matches);
|
|
5981
5659
|
}
|
|
5982
5660
|
if (fetcherKey) {
|
|
5983
|
-
return
|
|
5984
|
-
args,
|
|
5985
|
-
matches.findIndex((m) => m.shouldLoad),
|
|
5986
|
-
false,
|
|
5987
|
-
async (keyedResults) => {
|
|
5988
|
-
let results = await singleFetchLoaderFetcherStrategy(
|
|
5989
|
-
request,
|
|
5990
|
-
matches
|
|
5991
|
-
);
|
|
5992
|
-
Object.assign(keyedResults, results);
|
|
5993
|
-
},
|
|
5994
|
-
middlewareErrorHandler
|
|
5995
|
-
);
|
|
5661
|
+
return singleFetchLoaderFetcherStrategy(request, matches);
|
|
5996
5662
|
}
|
|
5997
|
-
|
|
5663
|
+
return singleFetchLoaderNavigationStrategy(
|
|
5998
5664
|
manifest,
|
|
5999
5665
|
routeModules,
|
|
6000
5666
|
getRouter(),
|
|
5667
|
+
request,
|
|
6001
5668
|
matches
|
|
6002
5669
|
);
|
|
6003
|
-
return runMiddlewarePipeline(
|
|
6004
|
-
args,
|
|
6005
|
-
lowestLoadingIndex,
|
|
6006
|
-
false,
|
|
6007
|
-
async (keyedResults) => {
|
|
6008
|
-
let results = await singleFetchLoaderNavigationStrategy(
|
|
6009
|
-
manifest,
|
|
6010
|
-
routeModules,
|
|
6011
|
-
getRouter(),
|
|
6012
|
-
request,
|
|
6013
|
-
matches
|
|
6014
|
-
);
|
|
6015
|
-
Object.assign(keyedResults, results);
|
|
6016
|
-
},
|
|
6017
|
-
middlewareErrorHandler
|
|
6018
|
-
);
|
|
6019
5670
|
};
|
|
6020
5671
|
}
|
|
6021
5672
|
async function singleFetchActionStrategy(request, matches) {
|
|
@@ -6045,20 +5696,6 @@ async function singleFetchActionStrategy(request, matches) {
|
|
|
6045
5696
|
}
|
|
6046
5697
|
};
|
|
6047
5698
|
}
|
|
6048
|
-
function isOptedOut(manifestRoute, routeModule, match, router) {
|
|
6049
|
-
return match.route.id in router.state.loaderData && manifestRoute && manifestRoute.hasLoader && routeModule && routeModule.shouldRevalidate;
|
|
6050
|
-
}
|
|
6051
|
-
function getLowestLoadingIndex(manifest, routeModules, router, matches) {
|
|
6052
|
-
let tailIdx = [...matches].reverse().findIndex(
|
|
6053
|
-
(m) => m.shouldLoad || !isOptedOut(
|
|
6054
|
-
manifest.routes[m.route.id],
|
|
6055
|
-
routeModules[m.route.id],
|
|
6056
|
-
m,
|
|
6057
|
-
router
|
|
6058
|
-
)
|
|
6059
|
-
);
|
|
6060
|
-
return tailIdx < 0 ? 0 : matches.length - 1 - tailIdx;
|
|
6061
|
-
}
|
|
6062
5699
|
async function singleFetchLoaderNavigationStrategy(manifest, routeModules, router, request, matches) {
|
|
6063
5700
|
let routesParams = /* @__PURE__ */ new Set();
|
|
6064
5701
|
let foundOptOutRoute = false;
|
|
@@ -6077,7 +5714,7 @@ async function singleFetchLoaderNavigationStrategy(manifest, routeModules, route
|
|
|
6077
5714
|
if (!router.state.initialized) {
|
|
6078
5715
|
return;
|
|
6079
5716
|
}
|
|
6080
|
-
if (
|
|
5717
|
+
if (m.route.id in router.state.loaderData && manifestRoute && manifestRoute.hasLoader && routeModules[m.route.id]?.shouldRevalidate) {
|
|
6081
5718
|
foundOptOutRoute = true;
|
|
6082
5719
|
return;
|
|
6083
5720
|
}
|
|
@@ -6477,8 +6114,8 @@ function createServerRoutes(manifest, routeModules, future, isSpaMode, parentId
|
|
|
6477
6114
|
// render, so just give it a no-op function so we can render down to the
|
|
6478
6115
|
// proper fallback
|
|
6479
6116
|
loader: route.hasLoader || route.hasClientLoader ? () => null : void 0
|
|
6480
|
-
// We don't need
|
|
6481
|
-
//
|
|
6117
|
+
// We don't need action/shouldRevalidate on these routes since they're
|
|
6118
|
+
// for a static render
|
|
6482
6119
|
};
|
|
6483
6120
|
let children = createServerRoutes(
|
|
6484
6121
|
manifest,
|
|
@@ -6544,6 +6181,21 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6544
6181
|
}
|
|
6545
6182
|
return fetchServerHandler(singleFetch);
|
|
6546
6183
|
}
|
|
6184
|
+
function prefetchModule(modulePath) {
|
|
6185
|
+
import(
|
|
6186
|
+
/* @vite-ignore */
|
|
6187
|
+
/* webpackIgnore: true */
|
|
6188
|
+
modulePath
|
|
6189
|
+
);
|
|
6190
|
+
}
|
|
6191
|
+
function prefetchRouteModuleChunks(route2) {
|
|
6192
|
+
if (route2.clientActionModule) {
|
|
6193
|
+
prefetchModule(route2.clientActionModule);
|
|
6194
|
+
}
|
|
6195
|
+
if (route2.clientLoaderModule) {
|
|
6196
|
+
prefetchModule(route2.clientLoaderModule);
|
|
6197
|
+
}
|
|
6198
|
+
}
|
|
6547
6199
|
async function prefetchStylesAndCallHandler(handler) {
|
|
6548
6200
|
let cachedModule = routeModulesCache[route.id];
|
|
6549
6201
|
let linkPrefetchPromise = cachedModule ? prefetchStyleLinks(route, cachedModule) : Promise.resolve();
|
|
@@ -6562,7 +6214,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6562
6214
|
Object.assign(dataRoute, {
|
|
6563
6215
|
...dataRoute,
|
|
6564
6216
|
...getRouteComponents(route, routeModule, isSpaMode),
|
|
6565
|
-
middleware: routeModule.clientMiddleware,
|
|
6566
6217
|
handle: routeModule.handle,
|
|
6567
6218
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
6568
6219
|
routeModule,
|
|
@@ -6575,7 +6226,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6575
6226
|
let hasInitialError = initialState && initialState.errors && route.id in initialState.errors;
|
|
6576
6227
|
let initialError = hasInitialError ? initialState?.errors?.[route.id] : void 0;
|
|
6577
6228
|
let isHydrationRequest = needsRevalidation == null && (routeModule.clientLoader?.hydrate === true || !route.hasLoader);
|
|
6578
|
-
dataRoute.loader = async ({ request, params
|
|
6229
|
+
dataRoute.loader = async ({ request, params }, singleFetch) => {
|
|
6579
6230
|
try {
|
|
6580
6231
|
let result = await prefetchStylesAndCallHandler(async () => {
|
|
6581
6232
|
invariant2(
|
|
@@ -6589,7 +6240,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6589
6240
|
return routeModule.clientLoader({
|
|
6590
6241
|
request,
|
|
6591
6242
|
params,
|
|
6592
|
-
context,
|
|
6593
6243
|
async serverLoader() {
|
|
6594
6244
|
preventInvalidServerHandlerCall("loader", route, isSpaMode);
|
|
6595
6245
|
if (isHydrationRequest) {
|
|
@@ -6614,7 +6264,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6614
6264
|
routeModule,
|
|
6615
6265
|
isSpaMode
|
|
6616
6266
|
);
|
|
6617
|
-
dataRoute.action = ({ request, params
|
|
6267
|
+
dataRoute.action = ({ request, params }, singleFetch) => {
|
|
6618
6268
|
return prefetchStylesAndCallHandler(async () => {
|
|
6619
6269
|
invariant2(
|
|
6620
6270
|
routeModule,
|
|
@@ -6629,7 +6279,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6629
6279
|
return routeModule.clientAction({
|
|
6630
6280
|
request,
|
|
6631
6281
|
params,
|
|
6632
|
-
context,
|
|
6633
6282
|
async serverAction() {
|
|
6634
6283
|
preventInvalidServerHandlerCall("action", route, isSpaMode);
|
|
6635
6284
|
return fetchServerAction(singleFetch);
|
|
@@ -6639,26 +6288,64 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6639
6288
|
};
|
|
6640
6289
|
} else {
|
|
6641
6290
|
if (!route.hasClientLoader) {
|
|
6642
|
-
dataRoute.loader = (
|
|
6291
|
+
dataRoute.loader = ({ request }, singleFetch) => prefetchStylesAndCallHandler(() => {
|
|
6643
6292
|
if (isSpaMode) return Promise.resolve(null);
|
|
6644
6293
|
return fetchServerLoader(singleFetch);
|
|
6645
6294
|
});
|
|
6295
|
+
} else if (route.clientLoaderModule) {
|
|
6296
|
+
dataRoute.loader = async (args, singleFetch) => {
|
|
6297
|
+
invariant2(route.clientLoaderModule);
|
|
6298
|
+
let { clientLoader } = await import(
|
|
6299
|
+
/* @vite-ignore */
|
|
6300
|
+
/* webpackIgnore: true */
|
|
6301
|
+
route.clientLoaderModule
|
|
6302
|
+
);
|
|
6303
|
+
return clientLoader({
|
|
6304
|
+
...args,
|
|
6305
|
+
async serverLoader() {
|
|
6306
|
+
preventInvalidServerHandlerCall("loader", route, isSpaMode);
|
|
6307
|
+
return fetchServerLoader(singleFetch);
|
|
6308
|
+
}
|
|
6309
|
+
});
|
|
6310
|
+
};
|
|
6646
6311
|
}
|
|
6647
6312
|
if (!route.hasClientAction) {
|
|
6648
|
-
dataRoute.action = (
|
|
6313
|
+
dataRoute.action = ({ request }, singleFetch) => prefetchStylesAndCallHandler(() => {
|
|
6649
6314
|
if (isSpaMode) {
|
|
6650
6315
|
throw noActionDefinedError("clientAction", route.id);
|
|
6651
6316
|
}
|
|
6652
6317
|
return fetchServerAction(singleFetch);
|
|
6653
6318
|
});
|
|
6319
|
+
} else if (route.clientActionModule) {
|
|
6320
|
+
dataRoute.action = async (args, singleFetch) => {
|
|
6321
|
+
invariant2(route.clientActionModule);
|
|
6322
|
+
prefetchRouteModuleChunks(route);
|
|
6323
|
+
let { clientAction } = await import(
|
|
6324
|
+
/* @vite-ignore */
|
|
6325
|
+
/* webpackIgnore: true */
|
|
6326
|
+
route.clientActionModule
|
|
6327
|
+
);
|
|
6328
|
+
return clientAction({
|
|
6329
|
+
...args,
|
|
6330
|
+
async serverAction() {
|
|
6331
|
+
preventInvalidServerHandlerCall("action", route, isSpaMode);
|
|
6332
|
+
return fetchServerAction(singleFetch);
|
|
6333
|
+
}
|
|
6334
|
+
});
|
|
6335
|
+
};
|
|
6654
6336
|
}
|
|
6655
6337
|
dataRoute.lazy = async () => {
|
|
6656
|
-
|
|
6338
|
+
if (route.clientLoaderModule || route.clientActionModule) {
|
|
6339
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
6340
|
+
}
|
|
6341
|
+
let modPromise = loadRouteModuleWithBlockingLinks(
|
|
6657
6342
|
route,
|
|
6658
6343
|
routeModulesCache
|
|
6659
6344
|
);
|
|
6345
|
+
prefetchRouteModuleChunks(route);
|
|
6346
|
+
let mod = await modPromise;
|
|
6660
6347
|
let lazyRoute = { ...mod };
|
|
6661
|
-
if (mod.clientLoader) {
|
|
6348
|
+
if (mod.clientLoader && !route.clientLoaderModule) {
|
|
6662
6349
|
let clientLoader = mod.clientLoader;
|
|
6663
6350
|
lazyRoute.loader = (args, singleFetch) => clientLoader({
|
|
6664
6351
|
...args,
|
|
@@ -6668,7 +6355,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6668
6355
|
}
|
|
6669
6356
|
});
|
|
6670
6357
|
}
|
|
6671
|
-
if (mod.clientAction) {
|
|
6358
|
+
if (mod.clientAction && !route.clientActionModule) {
|
|
6672
6359
|
let clientAction = mod.clientAction;
|
|
6673
6360
|
lazyRoute.action = (args, singleFetch) => clientAction({
|
|
6674
6361
|
...args,
|
|
@@ -6681,7 +6368,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6681
6368
|
return {
|
|
6682
6369
|
...lazyRoute.loader ? { loader: lazyRoute.loader } : {},
|
|
6683
6370
|
...lazyRoute.action ? { action: lazyRoute.action } : {},
|
|
6684
|
-
middleware: mod.clientMiddleware,
|
|
6685
6371
|
hasErrorBoundary: lazyRoute.hasErrorBoundary,
|
|
6686
6372
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
6687
6373
|
lazyRoute,
|
|
@@ -6739,7 +6425,6 @@ async function loadRouteModuleWithBlockingLinks(route, routeModules) {
|
|
|
6739
6425
|
return {
|
|
6740
6426
|
Component: getRouteModuleComponent(routeModule),
|
|
6741
6427
|
ErrorBoundary: routeModule.ErrorBoundary,
|
|
6742
|
-
clientMiddleware: routeModule.clientMiddleware,
|
|
6743
6428
|
clientAction: routeModule.clientAction,
|
|
6744
6429
|
clientLoader: routeModule.clientLoader,
|
|
6745
6430
|
handle: routeModule.handle,
|
|
@@ -7262,11 +6947,44 @@ function Scripts(props) {
|
|
|
7262
6947
|
let streamScript = "window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());";
|
|
7263
6948
|
let contextScript = staticContext ? `window.__reactRouterContext = ${serverHandoffString};${streamScript}` : " ";
|
|
7264
6949
|
let routeModulesScript = !isStatic ? " " : `${manifest.hmr?.runtime ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
|
|
7265
|
-
${matches.map(
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
)
|
|
7269
|
-
|
|
6950
|
+
${matches.map((match, routeIndex) => {
|
|
6951
|
+
let routeVarName = `route${routeIndex}`;
|
|
6952
|
+
let manifestEntry = manifest.routes[match.route.id];
|
|
6953
|
+
invariant2(manifestEntry, `Route ${match.route.id} not found in manifest`);
|
|
6954
|
+
let {
|
|
6955
|
+
clientActionModule,
|
|
6956
|
+
clientLoaderModule,
|
|
6957
|
+
hydrateFallbackModule,
|
|
6958
|
+
module
|
|
6959
|
+
} = manifestEntry;
|
|
6960
|
+
let chunks = [
|
|
6961
|
+
...clientActionModule ? [
|
|
6962
|
+
{
|
|
6963
|
+
module: clientActionModule,
|
|
6964
|
+
varName: `${routeVarName}_clientAction`
|
|
6965
|
+
}
|
|
6966
|
+
] : [],
|
|
6967
|
+
...clientLoaderModule ? [
|
|
6968
|
+
{
|
|
6969
|
+
module: clientLoaderModule,
|
|
6970
|
+
varName: `${routeVarName}_clientLoader`
|
|
6971
|
+
}
|
|
6972
|
+
] : [],
|
|
6973
|
+
...hydrateFallbackModule ? [
|
|
6974
|
+
{
|
|
6975
|
+
module: hydrateFallbackModule,
|
|
6976
|
+
varName: `${routeVarName}_HydrateFallback`
|
|
6977
|
+
}
|
|
6978
|
+
] : [],
|
|
6979
|
+
{ module, varName: `${routeVarName}_main` }
|
|
6980
|
+
];
|
|
6981
|
+
if (chunks.length === 1) {
|
|
6982
|
+
return `import * as ${routeVarName} from ${JSON.stringify(module)};`;
|
|
6983
|
+
}
|
|
6984
|
+
let chunkImportsSnippet = chunks.map((chunk) => `import * as ${chunk.varName} from "${chunk.module}";`).join("\n");
|
|
6985
|
+
let mergedChunksSnippet = `const ${routeVarName} = {${chunks.map((chunk) => `...${chunk.varName}`).join(",")}};`;
|
|
6986
|
+
return [chunkImportsSnippet, mergedChunksSnippet].join("\n");
|
|
6987
|
+
}).join("\n")}
|
|
7270
6988
|
${enableFogOfWar ? (
|
|
7271
6989
|
// Inline a minimal manifest with the SSR matches
|
|
7272
6990
|
`window.__reactRouterManifest = ${JSON.stringify(
|
|
@@ -7297,11 +7015,11 @@ import(${JSON.stringify(manifest.entry.module)});`;
|
|
|
7297
7015
|
}
|
|
7298
7016
|
));
|
|
7299
7017
|
}, []);
|
|
7300
|
-
let
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7018
|
+
let preloads = isHydrated ? [] : manifest.entry.imports.concat(
|
|
7019
|
+
getModuleLinkHrefs(matches, manifest, {
|
|
7020
|
+
includeHydrateFallback: true
|
|
7021
|
+
})
|
|
7022
|
+
);
|
|
7305
7023
|
return isHydrated ? null : /* @__PURE__ */ React9.createElement(React9.Fragment, null, !enableFogOfWar ? /* @__PURE__ */ React9.createElement(
|
|
7306
7024
|
"link",
|
|
7307
7025
|
{
|
|
@@ -7345,14 +7063,13 @@ function mergeRefs(...refs) {
|
|
|
7345
7063
|
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
7346
7064
|
try {
|
|
7347
7065
|
if (isBrowser) {
|
|
7348
|
-
window.__reactRouterVersion = "0.0.0-experimental-
|
|
7066
|
+
window.__reactRouterVersion = "0.0.0-experimental-df0f1dfda";
|
|
7349
7067
|
}
|
|
7350
7068
|
} catch (e) {
|
|
7351
7069
|
}
|
|
7352
7070
|
function createBrowserRouter(routes, opts) {
|
|
7353
7071
|
return createRouter({
|
|
7354
7072
|
basename: opts?.basename,
|
|
7355
|
-
context: opts?.context,
|
|
7356
7073
|
future: opts?.future,
|
|
7357
7074
|
history: createBrowserHistory({ window: opts?.window }),
|
|
7358
7075
|
hydrationData: opts?.hydrationData || parseHydrationData(),
|
|
@@ -7366,7 +7083,6 @@ function createBrowserRouter(routes, opts) {
|
|
|
7366
7083
|
function createHashRouter(routes, opts) {
|
|
7367
7084
|
return createRouter({
|
|
7368
7085
|
basename: opts?.basename,
|
|
7369
|
-
context: opts?.context,
|
|
7370
7086
|
future: opts?.future,
|
|
7371
7087
|
history: createHashHistory({ window: opts?.window }),
|
|
7372
7088
|
hydrationData: opts?.hydrationData || parseHydrationData(),
|
|
@@ -8508,14 +8224,13 @@ function createRoutesStub(routes, context = {}) {
|
|
|
8508
8224
|
isSpaMode: false
|
|
8509
8225
|
};
|
|
8510
8226
|
let patched = processRoutes(
|
|
8511
|
-
// @ts-expect-error
|
|
8512
|
-
// types compared to `AgnosticRouteObject`
|
|
8227
|
+
// @ts-expect-error loader/action context types don't match :/
|
|
8513
8228
|
convertRoutesToDataRoutes(routes, (r) => r),
|
|
8229
|
+
context,
|
|
8514
8230
|
remixContextRef.current.manifest,
|
|
8515
8231
|
remixContextRef.current.routeModules
|
|
8516
8232
|
);
|
|
8517
8233
|
routerRef.current = createMemoryRouter(patched, {
|
|
8518
|
-
context,
|
|
8519
8234
|
initialEntries,
|
|
8520
8235
|
initialIndex,
|
|
8521
8236
|
hydrationData
|
|
@@ -8524,13 +8239,14 @@ function createRoutesStub(routes, context = {}) {
|
|
|
8524
8239
|
return /* @__PURE__ */ React13.createElement(FrameworkContext.Provider, { value: remixContextRef.current }, /* @__PURE__ */ React13.createElement(RouterProvider, { router: routerRef.current }));
|
|
8525
8240
|
};
|
|
8526
8241
|
}
|
|
8527
|
-
function processRoutes(routes, manifest, routeModules, parentId) {
|
|
8242
|
+
function processRoutes(routes, context, manifest, routeModules, parentId) {
|
|
8528
8243
|
return routes.map((route) => {
|
|
8529
8244
|
if (!route.id) {
|
|
8530
8245
|
throw new Error(
|
|
8531
8246
|
"Expected a route.id in @remix-run/testing processRoutes() function"
|
|
8532
8247
|
);
|
|
8533
8248
|
}
|
|
8249
|
+
let { loader, action } = route;
|
|
8534
8250
|
let newRoute = {
|
|
8535
8251
|
id: route.id,
|
|
8536
8252
|
path: route.path,
|
|
@@ -8538,8 +8254,8 @@ function processRoutes(routes, manifest, routeModules, parentId) {
|
|
|
8538
8254
|
Component: route.Component,
|
|
8539
8255
|
HydrateFallback: route.HydrateFallback,
|
|
8540
8256
|
ErrorBoundary: route.ErrorBoundary,
|
|
8541
|
-
action:
|
|
8542
|
-
loader:
|
|
8257
|
+
action: action ? (args) => action({ ...args, context }) : void 0,
|
|
8258
|
+
loader: loader ? (args) => loader({ ...args, context }) : void 0,
|
|
8543
8259
|
handle: route.handle,
|
|
8544
8260
|
shouldRevalidate: route.shouldRevalidate
|
|
8545
8261
|
};
|
|
@@ -8556,8 +8272,11 @@ function processRoutes(routes, manifest, routeModules, parentId) {
|
|
|
8556
8272
|
hasClientAction: false,
|
|
8557
8273
|
hasClientLoader: false,
|
|
8558
8274
|
hasErrorBoundary: route.ErrorBoundary != null,
|
|
8559
|
-
|
|
8560
|
-
|
|
8275
|
+
// any need for these?
|
|
8276
|
+
module: "build/stub-path-to-module.js",
|
|
8277
|
+
clientActionModule: void 0,
|
|
8278
|
+
clientLoaderModule: void 0,
|
|
8279
|
+
hydrateFallbackModule: void 0
|
|
8561
8280
|
};
|
|
8562
8281
|
manifest.routes[newRoute.id] = entryRoute;
|
|
8563
8282
|
routeModules[route.id] = {
|
|
@@ -8571,6 +8290,7 @@ function processRoutes(routes, manifest, routeModules, parentId) {
|
|
|
8571
8290
|
if (route.children) {
|
|
8572
8291
|
newRoute.children = processRoutes(
|
|
8573
8292
|
route.children,
|
|
8293
|
+
context,
|
|
8574
8294
|
manifest,
|
|
8575
8295
|
routeModules,
|
|
8576
8296
|
newRoute.id
|
|
@@ -8931,7 +8651,6 @@ function createStaticHandlerDataRoutes(manifest, future, parentId = "", routesBy
|
|
|
8931
8651
|
hasErrorBoundary: route.id === "root" || route.module.ErrorBoundary != null,
|
|
8932
8652
|
id: route.id,
|
|
8933
8653
|
path: route.path,
|
|
8934
|
-
middleware: route.module.middleware,
|
|
8935
8654
|
// Need to use RR's version in the param typed here to permit the optional
|
|
8936
8655
|
// context even though we know it'll always be provided in remix
|
|
8937
8656
|
loader: route.module.loader ? async (args) => {
|
|
@@ -9067,15 +8786,35 @@ function prependCookies(parentHeaders, childHeaders) {
|
|
|
9067
8786
|
let parentSetCookieString = parentHeaders.get("Set-Cookie");
|
|
9068
8787
|
if (parentSetCookieString) {
|
|
9069
8788
|
let cookies = splitCookiesString(parentSetCookieString);
|
|
8789
|
+
let childCookies = new Set(childHeaders.getSetCookie());
|
|
9070
8790
|
cookies.forEach((cookie) => {
|
|
9071
|
-
|
|
8791
|
+
if (!childCookies.has(cookie)) {
|
|
8792
|
+
childHeaders.append("Set-Cookie", cookie);
|
|
8793
|
+
}
|
|
9072
8794
|
});
|
|
9073
8795
|
}
|
|
9074
8796
|
}
|
|
9075
8797
|
|
|
9076
8798
|
// lib/server-runtime/single-fetch.ts
|
|
9077
|
-
var NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([100, 101, 204, 205, 304]);
|
|
9078
8799
|
var SINGLE_FETCH_REDIRECT_STATUS = 202;
|
|
8800
|
+
function getSingleFetchDataStrategy2({
|
|
8801
|
+
isActionDataRequest,
|
|
8802
|
+
loadRouteIds
|
|
8803
|
+
} = {}) {
|
|
8804
|
+
return async ({ request, matches }) => {
|
|
8805
|
+
if (isActionDataRequest && request.method === "GET") {
|
|
8806
|
+
return {};
|
|
8807
|
+
}
|
|
8808
|
+
let matchesToLoad = loadRouteIds ? matches.filter((m) => loadRouteIds.includes(m.route.id)) : matches;
|
|
8809
|
+
let results = await Promise.all(
|
|
8810
|
+
matchesToLoad.map((match) => match.resolve())
|
|
8811
|
+
);
|
|
8812
|
+
return results.reduce(
|
|
8813
|
+
(acc, result, i) => Object.assign(acc, { [matchesToLoad[i].route.id]: result }),
|
|
8814
|
+
{}
|
|
8815
|
+
);
|
|
8816
|
+
};
|
|
8817
|
+
}
|
|
9079
8818
|
async function singleFetchAction(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
|
|
9080
8819
|
try {
|
|
9081
8820
|
let handlerRequest = new Request(handlerUrl, {
|
|
@@ -9088,46 +8827,12 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
|
|
|
9088
8827
|
let result = await staticHandler.query(handlerRequest, {
|
|
9089
8828
|
requestContext: loadContext,
|
|
9090
8829
|
skipLoaderErrorBubbling: true,
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
9095
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
9096
|
-
result: getSingleFetchRedirect(
|
|
9097
|
-
context.statusCode,
|
|
9098
|
-
headers,
|
|
9099
|
-
build.basename
|
|
9100
|
-
),
|
|
9101
|
-
headers,
|
|
9102
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
9103
|
-
});
|
|
9104
|
-
}
|
|
9105
|
-
if (context.errors) {
|
|
9106
|
-
Object.values(context.errors).forEach((err) => {
|
|
9107
|
-
if (!isRouteErrorResponse(err) || err.error) {
|
|
9108
|
-
handleError(err);
|
|
9109
|
-
}
|
|
9110
|
-
});
|
|
9111
|
-
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9112
|
-
}
|
|
9113
|
-
let singleFetchResult;
|
|
9114
|
-
if (context.errors) {
|
|
9115
|
-
singleFetchResult = { error: Object.values(context.errors)[0] };
|
|
9116
|
-
} else {
|
|
9117
|
-
singleFetchResult = {
|
|
9118
|
-
data: Object.values(context.actionData || {})[0]
|
|
9119
|
-
};
|
|
9120
|
-
}
|
|
9121
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
9122
|
-
result: singleFetchResult,
|
|
9123
|
-
headers,
|
|
9124
|
-
status: context.statusCode
|
|
9125
|
-
});
|
|
9126
|
-
}
|
|
8830
|
+
dataStrategy: getSingleFetchDataStrategy2({
|
|
8831
|
+
isActionDataRequest: true
|
|
8832
|
+
})
|
|
9127
8833
|
});
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
8834
|
+
if (isResponse(result)) {
|
|
8835
|
+
return {
|
|
9131
8836
|
result: getSingleFetchRedirect(
|
|
9132
8837
|
result.status,
|
|
9133
8838
|
result.headers,
|
|
@@ -9135,16 +8840,47 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
|
|
|
9135
8840
|
),
|
|
9136
8841
|
headers: result.headers,
|
|
9137
8842
|
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
8843
|
+
};
|
|
8844
|
+
}
|
|
8845
|
+
let context = result;
|
|
8846
|
+
let headers = getDocumentHeaders(build, context);
|
|
8847
|
+
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
8848
|
+
return {
|
|
8849
|
+
result: getSingleFetchRedirect(
|
|
8850
|
+
context.statusCode,
|
|
8851
|
+
headers,
|
|
8852
|
+
build.basename
|
|
8853
|
+
),
|
|
8854
|
+
headers,
|
|
8855
|
+
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
8856
|
+
};
|
|
8857
|
+
}
|
|
8858
|
+
if (context.errors) {
|
|
8859
|
+
Object.values(context.errors).forEach((err) => {
|
|
8860
|
+
if (!isRouteErrorResponse(err) || err.error) {
|
|
8861
|
+
handleError(err);
|
|
8862
|
+
}
|
|
9138
8863
|
});
|
|
8864
|
+
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9139
8865
|
}
|
|
9140
|
-
|
|
8866
|
+
let singleFetchResult;
|
|
8867
|
+
if (context.errors) {
|
|
8868
|
+
singleFetchResult = { error: Object.values(context.errors)[0] };
|
|
8869
|
+
} else {
|
|
8870
|
+
singleFetchResult = { data: Object.values(context.actionData || {})[0] };
|
|
8871
|
+
}
|
|
8872
|
+
return {
|
|
8873
|
+
result: singleFetchResult,
|
|
8874
|
+
headers,
|
|
8875
|
+
status: context.statusCode
|
|
8876
|
+
};
|
|
9141
8877
|
} catch (error) {
|
|
9142
8878
|
handleError(error);
|
|
9143
|
-
return
|
|
8879
|
+
return {
|
|
9144
8880
|
result: { error },
|
|
9145
8881
|
headers: new Headers(),
|
|
9146
8882
|
status: 500
|
|
9147
|
-
}
|
|
8883
|
+
};
|
|
9148
8884
|
}
|
|
9149
8885
|
}
|
|
9150
8886
|
async function singleFetchLoaders(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
|
|
@@ -9153,61 +8889,16 @@ async function singleFetchLoaders(build, serverMode, staticHandler, request, han
|
|
|
9153
8889
|
headers: request.headers,
|
|
9154
8890
|
signal: request.signal
|
|
9155
8891
|
});
|
|
9156
|
-
let
|
|
9157
|
-
let loadRouteIds = routesParam ? new Set(routesParam.split(",")) : null;
|
|
8892
|
+
let loadRouteIds = new URL(request.url).searchParams.get("_routes")?.split(",") || void 0;
|
|
9158
8893
|
let result = await staticHandler.query(handlerRequest, {
|
|
9159
8894
|
requestContext: loadContext,
|
|
9160
|
-
filterMatchesToLoad: (m) => !loadRouteIds || loadRouteIds.has(m.route.id),
|
|
9161
8895
|
skipLoaderErrorBubbling: true,
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
9166
|
-
result: {
|
|
9167
|
-
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
9168
|
-
context.statusCode,
|
|
9169
|
-
headers,
|
|
9170
|
-
build.basename
|
|
9171
|
-
)
|
|
9172
|
-
},
|
|
9173
|
-
headers,
|
|
9174
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
9175
|
-
});
|
|
9176
|
-
}
|
|
9177
|
-
if (context.errors) {
|
|
9178
|
-
Object.values(context.errors).forEach((err) => {
|
|
9179
|
-
if (!isRouteErrorResponse(err) || err.error) {
|
|
9180
|
-
handleError(err);
|
|
9181
|
-
}
|
|
9182
|
-
});
|
|
9183
|
-
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9184
|
-
}
|
|
9185
|
-
let results = {};
|
|
9186
|
-
let loadedMatches = new Set(
|
|
9187
|
-
context.matches.filter(
|
|
9188
|
-
(m) => loadRouteIds ? loadRouteIds.has(m.route.id) : m.route.loader != null
|
|
9189
|
-
).map((m) => m.route.id)
|
|
9190
|
-
);
|
|
9191
|
-
if (context.errors) {
|
|
9192
|
-
for (let [id, error] of Object.entries(context.errors)) {
|
|
9193
|
-
results[id] = { error };
|
|
9194
|
-
}
|
|
9195
|
-
}
|
|
9196
|
-
for (let [id, data2] of Object.entries(context.loaderData)) {
|
|
9197
|
-
if (!(id in results) && loadedMatches.has(id)) {
|
|
9198
|
-
results[id] = { data: data2 };
|
|
9199
|
-
}
|
|
9200
|
-
}
|
|
9201
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
9202
|
-
result: results,
|
|
9203
|
-
headers,
|
|
9204
|
-
status: context.statusCode
|
|
9205
|
-
});
|
|
9206
|
-
}
|
|
8896
|
+
dataStrategy: getSingleFetchDataStrategy2({
|
|
8897
|
+
loadRouteIds
|
|
8898
|
+
})
|
|
9207
8899
|
});
|
|
9208
|
-
|
|
9209
|
-
|
|
9210
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
8900
|
+
if (isResponse(result)) {
|
|
8901
|
+
return {
|
|
9211
8902
|
result: {
|
|
9212
8903
|
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
9213
8904
|
result.status,
|
|
@@ -9217,41 +8908,56 @@ async function singleFetchLoaders(build, serverMode, staticHandler, request, han
|
|
|
9217
8908
|
},
|
|
9218
8909
|
headers: result.headers,
|
|
9219
8910
|
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
8911
|
+
};
|
|
8912
|
+
}
|
|
8913
|
+
let context = result;
|
|
8914
|
+
let headers = getDocumentHeaders(build, context);
|
|
8915
|
+
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
8916
|
+
return {
|
|
8917
|
+
result: {
|
|
8918
|
+
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
8919
|
+
context.statusCode,
|
|
8920
|
+
headers,
|
|
8921
|
+
build.basename
|
|
8922
|
+
)
|
|
8923
|
+
},
|
|
8924
|
+
headers,
|
|
8925
|
+
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
8926
|
+
};
|
|
8927
|
+
}
|
|
8928
|
+
if (context.errors) {
|
|
8929
|
+
Object.values(context.errors).forEach((err) => {
|
|
8930
|
+
if (!isRouteErrorResponse(err) || err.error) {
|
|
8931
|
+
handleError(err);
|
|
8932
|
+
}
|
|
9220
8933
|
});
|
|
8934
|
+
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9221
8935
|
}
|
|
9222
|
-
|
|
8936
|
+
let results = {};
|
|
8937
|
+
let loadedMatches = loadRouteIds ? context.matches.filter(
|
|
8938
|
+
(m) => m.route.loader && loadRouteIds.includes(m.route.id)
|
|
8939
|
+
) : context.matches;
|
|
8940
|
+
loadedMatches.forEach((m) => {
|
|
8941
|
+
let { id } = m.route;
|
|
8942
|
+
if (context.errors && context.errors.hasOwnProperty(id)) {
|
|
8943
|
+
results[id] = { error: context.errors[id] };
|
|
8944
|
+
} else if (context.loaderData.hasOwnProperty(id)) {
|
|
8945
|
+
results[id] = { data: context.loaderData[id] };
|
|
8946
|
+
}
|
|
8947
|
+
});
|
|
8948
|
+
return {
|
|
8949
|
+
result: results,
|
|
8950
|
+
headers,
|
|
8951
|
+
status: context.statusCode
|
|
8952
|
+
};
|
|
9223
8953
|
} catch (error) {
|
|
9224
8954
|
handleError(error);
|
|
9225
|
-
return
|
|
8955
|
+
return {
|
|
9226
8956
|
result: { root: { error } },
|
|
9227
8957
|
headers: new Headers(),
|
|
9228
8958
|
status: 500
|
|
9229
|
-
}
|
|
9230
|
-
}
|
|
9231
|
-
}
|
|
9232
|
-
function generateSingleFetchResponse(request, build, serverMode, {
|
|
9233
|
-
result,
|
|
9234
|
-
headers,
|
|
9235
|
-
status
|
|
9236
|
-
}) {
|
|
9237
|
-
let resultHeaders = new Headers(headers);
|
|
9238
|
-
resultHeaders.set("X-Remix-Response", "yes");
|
|
9239
|
-
if (NO_BODY_STATUS_CODES.has(status)) {
|
|
9240
|
-
return new Response(null, { status, headers: resultHeaders });
|
|
8959
|
+
};
|
|
9241
8960
|
}
|
|
9242
|
-
resultHeaders.set("Content-Type", "text/x-script");
|
|
9243
|
-
return new Response(
|
|
9244
|
-
encodeViaTurboStream(
|
|
9245
|
-
result,
|
|
9246
|
-
request.signal,
|
|
9247
|
-
build.entry.module.streamTimeout,
|
|
9248
|
-
serverMode
|
|
9249
|
-
),
|
|
9250
|
-
{
|
|
9251
|
-
status: status || 200,
|
|
9252
|
-
headers: resultHeaders
|
|
9253
|
-
}
|
|
9254
|
-
);
|
|
9255
8961
|
}
|
|
9256
8962
|
function getSingleFetchRedirect(status, headers, basename) {
|
|
9257
8963
|
let redirect2 = headers.get("Location");
|
|
@@ -9314,6 +9020,7 @@ function encodeViaTurboStream(data2, requestSignal, streamTimeout, serverMode) {
|
|
|
9314
9020
|
}
|
|
9315
9021
|
|
|
9316
9022
|
// lib/server-runtime/server.ts
|
|
9023
|
+
var NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([100, 101, 204, 205, 304]);
|
|
9317
9024
|
function derive(build, mode) {
|
|
9318
9025
|
let routes = createRoutes(build.routes);
|
|
9319
9026
|
let dataRoutes = createStaticHandlerDataRoutes(build.routes, build.future);
|
|
@@ -9493,7 +9200,7 @@ async function handleManifestRequest(build, routes, url) {
|
|
|
9493
9200
|
return new Response("Invalid Request", { status: 400 });
|
|
9494
9201
|
}
|
|
9495
9202
|
async function handleSingleFetchRequest(serverMode, build, staticHandler, request, handlerUrl, loadContext, handleError) {
|
|
9496
|
-
let
|
|
9203
|
+
let { result, headers, status } = request.method !== "GET" ? await singleFetchAction(
|
|
9497
9204
|
build,
|
|
9498
9205
|
serverMode,
|
|
9499
9206
|
staticHandler,
|
|
@@ -9510,67 +9217,129 @@ async function handleSingleFetchRequest(serverMode, build, staticHandler, reques
|
|
|
9510
9217
|
loadContext,
|
|
9511
9218
|
handleError
|
|
9512
9219
|
);
|
|
9513
|
-
|
|
9220
|
+
let resultHeaders = new Headers(headers);
|
|
9221
|
+
resultHeaders.set("X-Remix-Response", "yes");
|
|
9222
|
+
if (NO_BODY_STATUS_CODES.has(status)) {
|
|
9223
|
+
return new Response(null, { status, headers: resultHeaders });
|
|
9224
|
+
}
|
|
9225
|
+
resultHeaders.set("Content-Type", "text/x-script");
|
|
9226
|
+
return new Response(
|
|
9227
|
+
encodeViaTurboStream(
|
|
9228
|
+
result,
|
|
9229
|
+
request.signal,
|
|
9230
|
+
build.entry.module.streamTimeout,
|
|
9231
|
+
serverMode
|
|
9232
|
+
),
|
|
9233
|
+
{
|
|
9234
|
+
status: status || 200,
|
|
9235
|
+
headers: resultHeaders
|
|
9236
|
+
}
|
|
9237
|
+
);
|
|
9514
9238
|
}
|
|
9515
9239
|
async function handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, criticalCss) {
|
|
9240
|
+
let context;
|
|
9516
9241
|
try {
|
|
9517
|
-
|
|
9518
|
-
requestContext: loadContext
|
|
9519
|
-
respond: renderHtml
|
|
9242
|
+
context = await staticHandler.query(request, {
|
|
9243
|
+
requestContext: loadContext
|
|
9520
9244
|
});
|
|
9521
|
-
invariant3(
|
|
9522
|
-
isResponse(response),
|
|
9523
|
-
"Expected a Response to be returned from query"
|
|
9524
|
-
);
|
|
9525
|
-
return response;
|
|
9526
9245
|
} catch (error) {
|
|
9527
9246
|
handleError(error);
|
|
9528
9247
|
return new Response(null, { status: 500 });
|
|
9529
9248
|
}
|
|
9530
|
-
|
|
9531
|
-
|
|
9532
|
-
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
|
|
9536
|
-
|
|
9249
|
+
if (isResponse(context)) {
|
|
9250
|
+
return context;
|
|
9251
|
+
}
|
|
9252
|
+
let headers = getDocumentHeaders(build, context);
|
|
9253
|
+
if (NO_BODY_STATUS_CODES.has(context.statusCode)) {
|
|
9254
|
+
return new Response(null, { status: context.statusCode, headers });
|
|
9255
|
+
}
|
|
9256
|
+
if (context.errors) {
|
|
9257
|
+
Object.values(context.errors).forEach((err) => {
|
|
9258
|
+
if (!isRouteErrorResponse(err) || err.error) {
|
|
9259
|
+
handleError(err);
|
|
9260
|
+
}
|
|
9261
|
+
});
|
|
9262
|
+
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9263
|
+
}
|
|
9264
|
+
let state = {
|
|
9265
|
+
loaderData: context.loaderData,
|
|
9266
|
+
actionData: context.actionData,
|
|
9267
|
+
errors: serializeErrors2(context.errors, serverMode)
|
|
9268
|
+
};
|
|
9269
|
+
let entryContext = {
|
|
9270
|
+
manifest: build.assets,
|
|
9271
|
+
routeModules: createEntryRouteModules(build.routes),
|
|
9272
|
+
staticHandlerContext: context,
|
|
9273
|
+
criticalCss,
|
|
9274
|
+
serverHandoffString: createServerHandoffString({
|
|
9275
|
+
basename: build.basename,
|
|
9276
|
+
criticalCss,
|
|
9277
|
+
future: build.future,
|
|
9278
|
+
isSpaMode: build.isSpaMode
|
|
9279
|
+
}),
|
|
9280
|
+
serverHandoffStream: encodeViaTurboStream(
|
|
9281
|
+
state,
|
|
9282
|
+
request.signal,
|
|
9283
|
+
build.entry.module.streamTimeout,
|
|
9284
|
+
serverMode
|
|
9285
|
+
),
|
|
9286
|
+
renderMeta: {},
|
|
9287
|
+
future: build.future,
|
|
9288
|
+
isSpaMode: build.isSpaMode,
|
|
9289
|
+
serializeError: (err) => serializeError(err, serverMode)
|
|
9290
|
+
};
|
|
9291
|
+
let handleDocumentRequestFunction = build.entry.module.default;
|
|
9292
|
+
try {
|
|
9293
|
+
return await handleDocumentRequestFunction(
|
|
9294
|
+
request,
|
|
9295
|
+
context.statusCode,
|
|
9296
|
+
headers,
|
|
9297
|
+
entryContext,
|
|
9298
|
+
loadContext
|
|
9299
|
+
);
|
|
9300
|
+
} catch (error) {
|
|
9301
|
+
handleError(error);
|
|
9302
|
+
let errorForSecondRender = error;
|
|
9303
|
+
if (isResponse(error)) {
|
|
9304
|
+
try {
|
|
9305
|
+
let data2 = await unwrapResponse(error);
|
|
9306
|
+
errorForSecondRender = new ErrorResponseImpl(
|
|
9307
|
+
error.status,
|
|
9308
|
+
error.statusText,
|
|
9309
|
+
data2
|
|
9310
|
+
);
|
|
9311
|
+
} catch (e) {
|
|
9312
|
+
}
|
|
9537
9313
|
}
|
|
9314
|
+
context = getStaticContextFromError(
|
|
9315
|
+
staticHandler.dataRoutes,
|
|
9316
|
+
context,
|
|
9317
|
+
errorForSecondRender
|
|
9318
|
+
);
|
|
9538
9319
|
if (context.errors) {
|
|
9539
|
-
Object.values(context.errors).forEach((err) => {
|
|
9540
|
-
if (!isRouteErrorResponse(err) || err.error) {
|
|
9541
|
-
handleError(err);
|
|
9542
|
-
}
|
|
9543
|
-
});
|
|
9544
9320
|
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9545
9321
|
}
|
|
9546
|
-
let
|
|
9322
|
+
let state2 = {
|
|
9547
9323
|
loaderData: context.loaderData,
|
|
9548
9324
|
actionData: context.actionData,
|
|
9549
9325
|
errors: serializeErrors2(context.errors, serverMode)
|
|
9550
9326
|
};
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
routeModules: createEntryRouteModules(build.routes),
|
|
9327
|
+
entryContext = {
|
|
9328
|
+
...entryContext,
|
|
9554
9329
|
staticHandlerContext: context,
|
|
9555
|
-
criticalCss,
|
|
9556
9330
|
serverHandoffString: createServerHandoffString({
|
|
9557
9331
|
basename: build.basename,
|
|
9558
|
-
criticalCss,
|
|
9559
9332
|
future: build.future,
|
|
9560
9333
|
isSpaMode: build.isSpaMode
|
|
9561
9334
|
}),
|
|
9562
9335
|
serverHandoffStream: encodeViaTurboStream(
|
|
9563
|
-
|
|
9336
|
+
state2,
|
|
9564
9337
|
request.signal,
|
|
9565
9338
|
build.entry.module.streamTimeout,
|
|
9566
9339
|
serverMode
|
|
9567
9340
|
),
|
|
9568
|
-
renderMeta: {}
|
|
9569
|
-
future: build.future,
|
|
9570
|
-
isSpaMode: build.isSpaMode,
|
|
9571
|
-
serializeError: (err) => serializeError(err, serverMode)
|
|
9341
|
+
renderMeta: {}
|
|
9572
9342
|
};
|
|
9573
|
-
let handleDocumentRequestFunction = build.entry.module.default;
|
|
9574
9343
|
try {
|
|
9575
9344
|
return await handleDocumentRequestFunction(
|
|
9576
9345
|
request,
|
|
@@ -9579,61 +9348,9 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
|
|
|
9579
9348
|
entryContext,
|
|
9580
9349
|
loadContext
|
|
9581
9350
|
);
|
|
9582
|
-
} catch (
|
|
9583
|
-
handleError(
|
|
9584
|
-
|
|
9585
|
-
if (isResponse(error)) {
|
|
9586
|
-
try {
|
|
9587
|
-
let data2 = await unwrapResponse(error);
|
|
9588
|
-
errorForSecondRender = new ErrorResponseImpl(
|
|
9589
|
-
error.status,
|
|
9590
|
-
error.statusText,
|
|
9591
|
-
data2
|
|
9592
|
-
);
|
|
9593
|
-
} catch (e) {
|
|
9594
|
-
}
|
|
9595
|
-
}
|
|
9596
|
-
context = getStaticContextFromError(
|
|
9597
|
-
staticHandler.dataRoutes,
|
|
9598
|
-
context,
|
|
9599
|
-
errorForSecondRender
|
|
9600
|
-
);
|
|
9601
|
-
if (context.errors) {
|
|
9602
|
-
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9603
|
-
}
|
|
9604
|
-
let state2 = {
|
|
9605
|
-
loaderData: context.loaderData,
|
|
9606
|
-
actionData: context.actionData,
|
|
9607
|
-
errors: serializeErrors2(context.errors, serverMode)
|
|
9608
|
-
};
|
|
9609
|
-
entryContext = {
|
|
9610
|
-
...entryContext,
|
|
9611
|
-
staticHandlerContext: context,
|
|
9612
|
-
serverHandoffString: createServerHandoffString({
|
|
9613
|
-
basename: build.basename,
|
|
9614
|
-
future: build.future,
|
|
9615
|
-
isSpaMode: build.isSpaMode
|
|
9616
|
-
}),
|
|
9617
|
-
serverHandoffStream: encodeViaTurboStream(
|
|
9618
|
-
state2,
|
|
9619
|
-
request.signal,
|
|
9620
|
-
build.entry.module.streamTimeout,
|
|
9621
|
-
serverMode
|
|
9622
|
-
),
|
|
9623
|
-
renderMeta: {}
|
|
9624
|
-
};
|
|
9625
|
-
try {
|
|
9626
|
-
return await handleDocumentRequestFunction(
|
|
9627
|
-
request,
|
|
9628
|
-
context.statusCode,
|
|
9629
|
-
headers,
|
|
9630
|
-
entryContext,
|
|
9631
|
-
loadContext
|
|
9632
|
-
);
|
|
9633
|
-
} catch (error2) {
|
|
9634
|
-
handleError(error2);
|
|
9635
|
-
return returnLastResortErrorResponse(error2, serverMode);
|
|
9636
|
-
}
|
|
9351
|
+
} catch (error2) {
|
|
9352
|
+
handleError(error2);
|
|
9353
|
+
return returnLastResortErrorResponse(error2, serverMode);
|
|
9637
9354
|
}
|
|
9638
9355
|
}
|
|
9639
9356
|
}
|
|
@@ -9641,16 +9358,15 @@ async function handleResourceRequest(serverMode, staticHandler, routeId, request
|
|
|
9641
9358
|
try {
|
|
9642
9359
|
let response = await staticHandler.queryRoute(request, {
|
|
9643
9360
|
routeId,
|
|
9644
|
-
requestContext: loadContext
|
|
9645
|
-
async respond(ctx) {
|
|
9646
|
-
return ctx;
|
|
9647
|
-
}
|
|
9361
|
+
requestContext: loadContext
|
|
9648
9362
|
});
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
)
|
|
9653
|
-
|
|
9363
|
+
if (isResponse(response)) {
|
|
9364
|
+
return response;
|
|
9365
|
+
}
|
|
9366
|
+
if (typeof response === "string") {
|
|
9367
|
+
return new Response(response);
|
|
9368
|
+
}
|
|
9369
|
+
return Response.json(response);
|
|
9654
9370
|
} catch (error) {
|
|
9655
9371
|
if (isResponse(error)) {
|
|
9656
9372
|
error.headers.set("X-Remix-Catch", "yes");
|
|
@@ -9662,13 +9378,6 @@ async function handleResourceRequest(serverMode, staticHandler, routeId, request
|
|
|
9662
9378
|
}
|
|
9663
9379
|
return errorResponseToJson(error, serverMode);
|
|
9664
9380
|
}
|
|
9665
|
-
if (error instanceof Error && error.message === "Expected a response from queryRoute") {
|
|
9666
|
-
let newError = new Error(
|
|
9667
|
-
"Expected a Response to be returned from resource route handler"
|
|
9668
|
-
);
|
|
9669
|
-
handleError(newError);
|
|
9670
|
-
return returnLastResortErrorResponse(newError, serverMode);
|
|
9671
|
-
}
|
|
9672
9381
|
handleError(error);
|
|
9673
9382
|
return returnLastResortErrorResponse(error, serverMode);
|
|
9674
9383
|
}
|