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
|
*
|
|
@@ -1052,7 +1052,6 @@ function createRouter(init) {
|
|
|
1052
1052
|
);
|
|
1053
1053
|
let inFlightDataRoutes;
|
|
1054
1054
|
let basename = init.basename || "/";
|
|
1055
|
-
let routerContext = typeof init.context !== "undefined" ? init.context : {};
|
|
1056
1055
|
let dataStrategyImpl = init.dataStrategy || defaultDataStrategy;
|
|
1057
1056
|
let patchRoutesOnNavigationImpl = init.patchRoutesOnNavigation;
|
|
1058
1057
|
let future = {
|
|
@@ -1065,6 +1064,7 @@ function createRouter(init) {
|
|
|
1065
1064
|
let getScrollPosition = null;
|
|
1066
1065
|
let initialScrollRestored = init.hydrationData != null;
|
|
1067
1066
|
let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
|
|
1067
|
+
let initialMatchesIsFOW = false;
|
|
1068
1068
|
let initialErrors = null;
|
|
1069
1069
|
if (initialMatches == null && !patchRoutesOnNavigationImpl) {
|
|
1070
1070
|
let error = getInternalRouterError(404, {
|
|
@@ -1094,6 +1094,7 @@ function createRouter(init) {
|
|
|
1094
1094
|
init.history.location.pathname
|
|
1095
1095
|
);
|
|
1096
1096
|
if (fogOfWar.active && fogOfWar.matches) {
|
|
1097
|
+
initialMatchesIsFOW = true;
|
|
1097
1098
|
initialMatches = fogOfWar.matches;
|
|
1098
1099
|
}
|
|
1099
1100
|
} else if (initialMatches.some((m) => m.route.lazy)) {
|
|
@@ -1459,7 +1460,10 @@ function createRouter(init) {
|
|
|
1459
1460
|
pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
|
|
1460
1461
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
1461
1462
|
let loadingNavigation = opts && opts.overrideNavigation;
|
|
1462
|
-
let matches =
|
|
1463
|
+
let matches = opts?.initialHydration && state.matches && state.matches.length > 0 && !initialMatchesIsFOW ? (
|
|
1464
|
+
// `matchRoutes()` has already been called if we're in here via `router.initialize()`
|
|
1465
|
+
state.matches
|
|
1466
|
+
) : matchRoutes(routesToUse, location, basename);
|
|
1463
1467
|
let flushSync = (opts && opts.flushSync) === true;
|
|
1464
1468
|
let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
|
|
1465
1469
|
if (fogOfWar.active && fogOfWar.matches) {
|
|
@@ -1493,7 +1497,6 @@ function createRouter(init) {
|
|
|
1493
1497
|
pendingNavigationController.signal,
|
|
1494
1498
|
opts && opts.submission
|
|
1495
1499
|
);
|
|
1496
|
-
let scopedContext = { ...routerContext };
|
|
1497
1500
|
let pendingActionResult;
|
|
1498
1501
|
if (opts && opts.pendingError) {
|
|
1499
1502
|
pendingActionResult = [
|
|
@@ -1506,7 +1509,6 @@ function createRouter(init) {
|
|
|
1506
1509
|
location,
|
|
1507
1510
|
opts.submission,
|
|
1508
1511
|
matches,
|
|
1509
|
-
scopedContext,
|
|
1510
1512
|
fogOfWar.active,
|
|
1511
1513
|
{ replace: opts.replace, flushSync }
|
|
1512
1514
|
);
|
|
@@ -1547,7 +1549,6 @@ function createRouter(init) {
|
|
|
1547
1549
|
request,
|
|
1548
1550
|
location,
|
|
1549
1551
|
matches,
|
|
1550
|
-
scopedContext,
|
|
1551
1552
|
fogOfWar.active,
|
|
1552
1553
|
loadingNavigation,
|
|
1553
1554
|
opts && opts.submission,
|
|
@@ -1568,7 +1569,7 @@ function createRouter(init) {
|
|
|
1568
1569
|
errors
|
|
1569
1570
|
});
|
|
1570
1571
|
}
|
|
1571
|
-
async function handleAction(request, location, submission, matches,
|
|
1572
|
+
async function handleAction(request, location, submission, matches, isFogOfWar, opts = {}) {
|
|
1572
1573
|
interruptActiveLoads();
|
|
1573
1574
|
let navigation = getSubmittingNavigation(location, submission);
|
|
1574
1575
|
updateState({ navigation }, { flushSync: opts.flushSync === true });
|
|
@@ -1622,23 +1623,15 @@ function createRouter(init) {
|
|
|
1622
1623
|
})
|
|
1623
1624
|
};
|
|
1624
1625
|
} else {
|
|
1625
|
-
let results = await
|
|
1626
|
+
let results = await callDataStrategy(
|
|
1626
1627
|
"action",
|
|
1628
|
+
state,
|
|
1627
1629
|
request,
|
|
1628
1630
|
[actionMatch],
|
|
1629
1631
|
matches,
|
|
1630
|
-
scopedContext,
|
|
1631
1632
|
null
|
|
1632
1633
|
);
|
|
1633
1634
|
result = results[actionMatch.route.id];
|
|
1634
|
-
if (!result) {
|
|
1635
|
-
for (let match of matches) {
|
|
1636
|
-
if (results[match.route.id]) {
|
|
1637
|
-
result = results[match.route.id];
|
|
1638
|
-
break;
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
1635
|
if (request.signal.aborted) {
|
|
1643
1636
|
return { shortCircuited: true };
|
|
1644
1637
|
}
|
|
@@ -1676,7 +1669,7 @@ function createRouter(init) {
|
|
|
1676
1669
|
pendingActionResult: [actionMatch.route.id, result]
|
|
1677
1670
|
};
|
|
1678
1671
|
}
|
|
1679
|
-
async function handleLoaders(request, location, matches,
|
|
1672
|
+
async function handleLoaders(request, location, matches, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync, pendingActionResult) {
|
|
1680
1673
|
let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
|
|
1681
1674
|
let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
|
|
1682
1675
|
let shouldUpdateNavigationState = !isUninterruptedRevalidation && !initialHydration;
|
|
@@ -1786,11 +1779,11 @@ function createRouter(init) {
|
|
|
1786
1779
|
);
|
|
1787
1780
|
}
|
|
1788
1781
|
let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
|
1782
|
+
state,
|
|
1789
1783
|
matches,
|
|
1790
1784
|
matchesToLoad,
|
|
1791
1785
|
revalidatingFetchers,
|
|
1792
|
-
request
|
|
1793
|
-
scopedContext
|
|
1786
|
+
request
|
|
1794
1787
|
);
|
|
1795
1788
|
if (request.signal.aborted) {
|
|
1796
1789
|
return { shortCircuited: true };
|
|
@@ -1898,7 +1891,6 @@ function createRouter(init) {
|
|
|
1898
1891
|
return;
|
|
1899
1892
|
}
|
|
1900
1893
|
let match = getTargetMatch(matches, path);
|
|
1901
|
-
let scopedContext = { ...routerContext };
|
|
1902
1894
|
let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1903
1895
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
1904
1896
|
await handleFetcherAction(
|
|
@@ -1907,7 +1899,6 @@ function createRouter(init) {
|
|
|
1907
1899
|
path,
|
|
1908
1900
|
match,
|
|
1909
1901
|
matches,
|
|
1910
|
-
scopedContext,
|
|
1911
1902
|
fogOfWar.active,
|
|
1912
1903
|
flushSync,
|
|
1913
1904
|
preventScrollReset,
|
|
@@ -1922,14 +1913,13 @@ function createRouter(init) {
|
|
|
1922
1913
|
path,
|
|
1923
1914
|
match,
|
|
1924
1915
|
matches,
|
|
1925
|
-
scopedContext,
|
|
1926
1916
|
fogOfWar.active,
|
|
1927
1917
|
flushSync,
|
|
1928
1918
|
preventScrollReset,
|
|
1929
1919
|
submission
|
|
1930
1920
|
);
|
|
1931
1921
|
}
|
|
1932
|
-
async function handleFetcherAction(key, routeId, path, match, requestMatches,
|
|
1922
|
+
async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
1933
1923
|
interruptActiveLoads();
|
|
1934
1924
|
fetchLoadMatches.delete(key);
|
|
1935
1925
|
function detectAndHandle405Error(m) {
|
|
@@ -1987,12 +1977,12 @@ function createRouter(init) {
|
|
|
1987
1977
|
}
|
|
1988
1978
|
fetchControllers.set(key, abortController);
|
|
1989
1979
|
let originatingLoadId = incrementingLoadId;
|
|
1990
|
-
let actionResults = await
|
|
1980
|
+
let actionResults = await callDataStrategy(
|
|
1991
1981
|
"action",
|
|
1982
|
+
state,
|
|
1992
1983
|
fetchRequest,
|
|
1993
1984
|
[match],
|
|
1994
1985
|
requestMatches,
|
|
1995
|
-
scopedContext,
|
|
1996
1986
|
key
|
|
1997
1987
|
);
|
|
1998
1988
|
let actionResult = actionResults[match.route.id];
|
|
@@ -2076,11 +2066,11 @@ function createRouter(init) {
|
|
|
2076
2066
|
abortPendingFetchRevalidations
|
|
2077
2067
|
);
|
|
2078
2068
|
let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
|
2069
|
+
state,
|
|
2079
2070
|
matches,
|
|
2080
2071
|
matchesToLoad,
|
|
2081
2072
|
revalidatingFetchers,
|
|
2082
|
-
revalidationRequest
|
|
2083
|
-
scopedContext
|
|
2073
|
+
revalidationRequest
|
|
2084
2074
|
);
|
|
2085
2075
|
if (abortController.signal.aborted) {
|
|
2086
2076
|
return;
|
|
@@ -2147,7 +2137,7 @@ function createRouter(init) {
|
|
|
2147
2137
|
isRevalidationRequired = false;
|
|
2148
2138
|
}
|
|
2149
2139
|
}
|
|
2150
|
-
async function handleFetcherLoader(key, routeId, path, match, matches,
|
|
2140
|
+
async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
2151
2141
|
let existingFetcher = state.fetchers.get(key);
|
|
2152
2142
|
updateFetcherState(
|
|
2153
2143
|
key,
|
|
@@ -2189,12 +2179,12 @@ function createRouter(init) {
|
|
|
2189
2179
|
}
|
|
2190
2180
|
fetchControllers.set(key, abortController);
|
|
2191
2181
|
let originatingLoadId = incrementingLoadId;
|
|
2192
|
-
let results = await
|
|
2182
|
+
let results = await callDataStrategy(
|
|
2193
2183
|
"loader",
|
|
2184
|
+
state,
|
|
2194
2185
|
fetchRequest,
|
|
2195
2186
|
[match],
|
|
2196
2187
|
matches,
|
|
2197
|
-
scopedContext,
|
|
2198
2188
|
key
|
|
2199
2189
|
);
|
|
2200
2190
|
let result = results[match.route.id];
|
|
@@ -2296,20 +2286,20 @@ function createRouter(init) {
|
|
|
2296
2286
|
});
|
|
2297
2287
|
}
|
|
2298
2288
|
}
|
|
2299
|
-
async function
|
|
2289
|
+
async function callDataStrategy(type, state2, request, matchesToLoad, matches, fetcherKey) {
|
|
2300
2290
|
let results;
|
|
2301
2291
|
let dataResults = {};
|
|
2302
2292
|
try {
|
|
2303
2293
|
results = await callDataStrategyImpl(
|
|
2304
2294
|
dataStrategyImpl,
|
|
2305
2295
|
type,
|
|
2296
|
+
state2,
|
|
2306
2297
|
request,
|
|
2307
2298
|
matchesToLoad,
|
|
2308
2299
|
matches,
|
|
2309
2300
|
fetcherKey,
|
|
2310
2301
|
manifest,
|
|
2311
|
-
mapRouteProperties2
|
|
2312
|
-
scopedContext
|
|
2302
|
+
mapRouteProperties2
|
|
2313
2303
|
);
|
|
2314
2304
|
} catch (e) {
|
|
2315
2305
|
matchesToLoad.forEach((m) => {
|
|
@@ -2341,24 +2331,24 @@ function createRouter(init) {
|
|
|
2341
2331
|
}
|
|
2342
2332
|
return dataResults;
|
|
2343
2333
|
}
|
|
2344
|
-
async function callLoadersAndMaybeResolveData(matches, matchesToLoad, fetchersToLoad, request
|
|
2345
|
-
let loaderResultsPromise =
|
|
2334
|
+
async function callLoadersAndMaybeResolveData(state2, matches, matchesToLoad, fetchersToLoad, request) {
|
|
2335
|
+
let loaderResultsPromise = callDataStrategy(
|
|
2346
2336
|
"loader",
|
|
2337
|
+
state2,
|
|
2347
2338
|
request,
|
|
2348
2339
|
matchesToLoad,
|
|
2349
2340
|
matches,
|
|
2350
|
-
scopedContext,
|
|
2351
2341
|
null
|
|
2352
2342
|
);
|
|
2353
2343
|
let fetcherResultsPromise = Promise.all(
|
|
2354
2344
|
fetchersToLoad.map(async (f) => {
|
|
2355
2345
|
if (f.matches && f.match && f.controller) {
|
|
2356
|
-
let results = await
|
|
2346
|
+
let results = await callDataStrategy(
|
|
2357
2347
|
"loader",
|
|
2348
|
+
state2,
|
|
2358
2349
|
createClientSideRequest(init.history, f.path, f.controller.signal),
|
|
2359
2350
|
[f.match],
|
|
2360
2351
|
f.matches,
|
|
2361
|
-
scopedContext,
|
|
2362
2352
|
f.key
|
|
2363
2353
|
);
|
|
2364
2354
|
let result = results[f.match.route.id];
|
|
@@ -2734,21 +2724,17 @@ function createStaticHandler(routes, opts) {
|
|
|
2734
2724
|
);
|
|
2735
2725
|
async function query(request, {
|
|
2736
2726
|
requestContext,
|
|
2737
|
-
filterMatchesToLoad,
|
|
2738
2727
|
skipLoaderErrorBubbling,
|
|
2739
|
-
|
|
2740
|
-
dataStrategy,
|
|
2741
|
-
respond
|
|
2728
|
+
dataStrategy
|
|
2742
2729
|
} = {}) {
|
|
2743
2730
|
let url = new URL(request.url);
|
|
2744
2731
|
let method = request.method;
|
|
2745
2732
|
let location = createLocation("", createPath(url), null, "default");
|
|
2746
2733
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2747
|
-
let staticContext;
|
|
2748
2734
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
2749
2735
|
let error = getInternalRouterError(405, { method });
|
|
2750
2736
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
2751
|
-
|
|
2737
|
+
return {
|
|
2752
2738
|
basename,
|
|
2753
2739
|
location,
|
|
2754
2740
|
matches: methodNotAllowedMatches,
|
|
@@ -2764,7 +2750,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2764
2750
|
} else if (!matches) {
|
|
2765
2751
|
let error = getInternalRouterError(404, { pathname: location.pathname });
|
|
2766
2752
|
let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
2767
|
-
|
|
2753
|
+
return {
|
|
2768
2754
|
basename,
|
|
2769
2755
|
location,
|
|
2770
2756
|
matches: notFoundMatches,
|
|
@@ -2777,118 +2763,25 @@ function createStaticHandler(routes, opts) {
|
|
|
2777
2763
|
loaderHeaders: {},
|
|
2778
2764
|
actionHeaders: {}
|
|
2779
2765
|
};
|
|
2780
|
-
} else if (respond) {
|
|
2781
|
-
try {
|
|
2782
|
-
let tailIdx = [...matches].reverse().findIndex((m) => !filterMatchesToLoad || filterMatchesToLoad(m));
|
|
2783
|
-
let lowestLoadingIdx = tailIdx < 0 ? 0 : matches.length - 1 - tailIdx;
|
|
2784
|
-
let renderedStaticContext;
|
|
2785
|
-
let response = await runMiddlewarePipeline(
|
|
2786
|
-
{
|
|
2787
|
-
request,
|
|
2788
|
-
matches,
|
|
2789
|
-
params: matches[0].params,
|
|
2790
|
-
context: requestContext
|
|
2791
|
-
},
|
|
2792
|
-
lowestLoadingIdx,
|
|
2793
|
-
true,
|
|
2794
|
-
async () => {
|
|
2795
|
-
let result = await callQueryHandlers(
|
|
2796
|
-
request,
|
|
2797
|
-
location,
|
|
2798
|
-
matches,
|
|
2799
|
-
requestContext,
|
|
2800
|
-
dataStrategy || defaultDataStrategyWithoutMiddleware,
|
|
2801
|
-
skipLoaderErrorBubbling === true,
|
|
2802
|
-
null,
|
|
2803
|
-
filterMatchesToLoad || null,
|
|
2804
|
-
skipRevalidation === true
|
|
2805
|
-
);
|
|
2806
|
-
if (isResponse(result)) {
|
|
2807
|
-
return result;
|
|
2808
|
-
}
|
|
2809
|
-
renderedStaticContext = {
|
|
2810
|
-
location,
|
|
2811
|
-
basename,
|
|
2812
|
-
...result
|
|
2813
|
-
};
|
|
2814
|
-
let res = await respond(renderedStaticContext);
|
|
2815
|
-
return res;
|
|
2816
|
-
},
|
|
2817
|
-
async (e) => {
|
|
2818
|
-
if (isResponse(e.error)) {
|
|
2819
|
-
return e.error;
|
|
2820
|
-
}
|
|
2821
|
-
let boundary = findNearestBoundary(matches, e.routeId);
|
|
2822
|
-
let errorContext;
|
|
2823
|
-
if (renderedStaticContext) {
|
|
2824
|
-
if (e.routeId in renderedStaticContext.loaderData) {
|
|
2825
|
-
renderedStaticContext.loaderData[e.routeId] = void 0;
|
|
2826
|
-
}
|
|
2827
|
-
errorContext = getStaticContextFromError(
|
|
2828
|
-
dataRoutes,
|
|
2829
|
-
renderedStaticContext,
|
|
2830
|
-
e.error,
|
|
2831
|
-
boundary.route.id
|
|
2832
|
-
);
|
|
2833
|
-
} else {
|
|
2834
|
-
errorContext = {
|
|
2835
|
-
matches,
|
|
2836
|
-
location,
|
|
2837
|
-
basename,
|
|
2838
|
-
loaderData: {},
|
|
2839
|
-
actionData: null,
|
|
2840
|
-
errors: {
|
|
2841
|
-
[boundary.route.id]: e.error
|
|
2842
|
-
},
|
|
2843
|
-
statusCode: isRouteErrorResponse(e.error) ? e.error.status : 500,
|
|
2844
|
-
actionHeaders: {},
|
|
2845
|
-
loaderHeaders: {}
|
|
2846
|
-
};
|
|
2847
|
-
}
|
|
2848
|
-
let res = await respond(errorContext);
|
|
2849
|
-
return res;
|
|
2850
|
-
}
|
|
2851
|
-
);
|
|
2852
|
-
invariant(isResponse(response), "Expected a response in query()");
|
|
2853
|
-
return response;
|
|
2854
|
-
} catch (e) {
|
|
2855
|
-
if (isResponse(e)) {
|
|
2856
|
-
return e;
|
|
2857
|
-
}
|
|
2858
|
-
throw e;
|
|
2859
|
-
}
|
|
2860
|
-
} else {
|
|
2861
|
-
let result = await callQueryHandlers(
|
|
2862
|
-
request,
|
|
2863
|
-
location,
|
|
2864
|
-
matches,
|
|
2865
|
-
requestContext,
|
|
2866
|
-
dataStrategy || null,
|
|
2867
|
-
skipLoaderErrorBubbling === true,
|
|
2868
|
-
null,
|
|
2869
|
-
filterMatchesToLoad || null,
|
|
2870
|
-
skipRevalidation === true
|
|
2871
|
-
);
|
|
2872
|
-
if (isResponse(result)) {
|
|
2873
|
-
return result;
|
|
2874
|
-
}
|
|
2875
|
-
staticContext = {
|
|
2876
|
-
location,
|
|
2877
|
-
basename,
|
|
2878
|
-
...result
|
|
2879
|
-
};
|
|
2880
2766
|
}
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2767
|
+
let result = await queryImpl(
|
|
2768
|
+
request,
|
|
2769
|
+
location,
|
|
2770
|
+
matches,
|
|
2771
|
+
requestContext,
|
|
2772
|
+
dataStrategy || null,
|
|
2773
|
+
skipLoaderErrorBubbling === true,
|
|
2774
|
+
null
|
|
2775
|
+
);
|
|
2776
|
+
if (isResponse(result)) {
|
|
2777
|
+
return result;
|
|
2884
2778
|
}
|
|
2885
|
-
return
|
|
2779
|
+
return { location, basename, ...result };
|
|
2886
2780
|
}
|
|
2887
2781
|
async function queryRoute(request, {
|
|
2888
2782
|
routeId,
|
|
2889
2783
|
requestContext,
|
|
2890
|
-
dataStrategy
|
|
2891
|
-
respond
|
|
2784
|
+
dataStrategy
|
|
2892
2785
|
} = {}) {
|
|
2893
2786
|
let url = new URL(request.url);
|
|
2894
2787
|
let method = request.method;
|
|
@@ -2908,77 +2801,31 @@ function createStaticHandler(routes, opts) {
|
|
|
2908
2801
|
} else if (!match) {
|
|
2909
2802
|
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
2910
2803
|
}
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
match,
|
|
2930
|
-
null,
|
|
2931
|
-
false
|
|
2932
|
-
);
|
|
2933
|
-
if (isResponse(result)) {
|
|
2934
|
-
return respond(result);
|
|
2935
|
-
}
|
|
2936
|
-
let error = result.errors ? Object.values(result.errors)[0] : void 0;
|
|
2937
|
-
if (error !== void 0) {
|
|
2938
|
-
throw error;
|
|
2939
|
-
}
|
|
2940
|
-
throw new Error("Expected a response from queryRoute");
|
|
2941
|
-
},
|
|
2942
|
-
(e) => {
|
|
2943
|
-
if (isResponse(e.error)) {
|
|
2944
|
-
return respond(e.error);
|
|
2945
|
-
}
|
|
2946
|
-
return new Response(String(e.error), {
|
|
2947
|
-
status: 500,
|
|
2948
|
-
statusText: "Unexpected Server Error"
|
|
2949
|
-
});
|
|
2950
|
-
}
|
|
2951
|
-
);
|
|
2952
|
-
return response;
|
|
2953
|
-
} else {
|
|
2954
|
-
let result = await callQueryHandlers(
|
|
2955
|
-
request,
|
|
2956
|
-
location,
|
|
2957
|
-
matches,
|
|
2958
|
-
requestContext,
|
|
2959
|
-
dataStrategy || null,
|
|
2960
|
-
false,
|
|
2961
|
-
match,
|
|
2962
|
-
null,
|
|
2963
|
-
false
|
|
2964
|
-
);
|
|
2965
|
-
if (isResponse(result)) {
|
|
2966
|
-
return result;
|
|
2967
|
-
}
|
|
2968
|
-
let error = result.errors ? Object.values(result.errors)[0] : void 0;
|
|
2969
|
-
if (error !== void 0) {
|
|
2970
|
-
throw error;
|
|
2971
|
-
}
|
|
2972
|
-
if (result.actionData) {
|
|
2973
|
-
return Object.values(result.actionData)[0];
|
|
2974
|
-
}
|
|
2975
|
-
if (result.loaderData) {
|
|
2976
|
-
return Object.values(result.loaderData)[0];
|
|
2977
|
-
}
|
|
2978
|
-
return void 0;
|
|
2804
|
+
let result = await queryImpl(
|
|
2805
|
+
request,
|
|
2806
|
+
location,
|
|
2807
|
+
matches,
|
|
2808
|
+
requestContext,
|
|
2809
|
+
dataStrategy || null,
|
|
2810
|
+
false,
|
|
2811
|
+
match
|
|
2812
|
+
);
|
|
2813
|
+
if (isResponse(result)) {
|
|
2814
|
+
return result;
|
|
2815
|
+
}
|
|
2816
|
+
let error = result.errors ? Object.values(result.errors)[0] : void 0;
|
|
2817
|
+
if (error !== void 0) {
|
|
2818
|
+
throw error;
|
|
2819
|
+
}
|
|
2820
|
+
if (result.actionData) {
|
|
2821
|
+
return Object.values(result.actionData)[0];
|
|
2979
2822
|
}
|
|
2823
|
+
if (result.loaderData) {
|
|
2824
|
+
return Object.values(result.loaderData)[0];
|
|
2825
|
+
}
|
|
2826
|
+
return void 0;
|
|
2980
2827
|
}
|
|
2981
|
-
async function
|
|
2828
|
+
async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch) {
|
|
2982
2829
|
invariant(
|
|
2983
2830
|
request.signal,
|
|
2984
2831
|
"query()/queryRoute() requests must contain an AbortController signal"
|
|
@@ -2992,9 +2839,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2992
2839
|
requestContext,
|
|
2993
2840
|
dataStrategy,
|
|
2994
2841
|
skipLoaderErrorBubbling,
|
|
2995
|
-
routeMatch != null
|
|
2996
|
-
filterMatchesToLoad,
|
|
2997
|
-
skipRevalidation
|
|
2842
|
+
routeMatch != null
|
|
2998
2843
|
);
|
|
2999
2844
|
return result2;
|
|
3000
2845
|
}
|
|
@@ -3004,8 +2849,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3004
2849
|
requestContext,
|
|
3005
2850
|
dataStrategy,
|
|
3006
2851
|
skipLoaderErrorBubbling,
|
|
3007
|
-
routeMatch
|
|
3008
|
-
filterMatchesToLoad
|
|
2852
|
+
routeMatch
|
|
3009
2853
|
);
|
|
3010
2854
|
return isResponse(result) ? result : {
|
|
3011
2855
|
...result,
|
|
@@ -3025,7 +2869,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3025
2869
|
throw e;
|
|
3026
2870
|
}
|
|
3027
2871
|
}
|
|
3028
|
-
async function submit(request, matches, actionMatch, requestContext, dataStrategy, skipLoaderErrorBubbling, isRouteRequest
|
|
2872
|
+
async function submit(request, matches, actionMatch, requestContext, dataStrategy, skipLoaderErrorBubbling, isRouteRequest) {
|
|
3029
2873
|
let result;
|
|
3030
2874
|
if (!actionMatch.route.action && !actionMatch.route.lazy) {
|
|
3031
2875
|
let error = getInternalRouterError(405, {
|
|
@@ -3041,7 +2885,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3041
2885
|
error
|
|
3042
2886
|
};
|
|
3043
2887
|
} else {
|
|
3044
|
-
let results = await
|
|
2888
|
+
let results = await callDataStrategy(
|
|
3045
2889
|
"action",
|
|
3046
2890
|
request,
|
|
3047
2891
|
[actionMatch],
|
|
@@ -3079,36 +2923,6 @@ function createStaticHandler(routes, opts) {
|
|
|
3079
2923
|
actionHeaders: {}
|
|
3080
2924
|
};
|
|
3081
2925
|
}
|
|
3082
|
-
if (skipRevalidation) {
|
|
3083
|
-
if (isErrorResult(result)) {
|
|
3084
|
-
let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
|
|
3085
|
-
return {
|
|
3086
|
-
matches,
|
|
3087
|
-
loaderData: {},
|
|
3088
|
-
actionData: null,
|
|
3089
|
-
errors: {
|
|
3090
|
-
[boundaryMatch.route.id]: result.error
|
|
3091
|
-
},
|
|
3092
|
-
statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500,
|
|
3093
|
-
loaderHeaders: {},
|
|
3094
|
-
actionHeaders: {
|
|
3095
|
-
...result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
|
3096
|
-
}
|
|
3097
|
-
};
|
|
3098
|
-
} else {
|
|
3099
|
-
return {
|
|
3100
|
-
matches,
|
|
3101
|
-
loaderData: {},
|
|
3102
|
-
actionData: {
|
|
3103
|
-
[actionMatch.route.id]: result.data
|
|
3104
|
-
},
|
|
3105
|
-
errors: null,
|
|
3106
|
-
statusCode: result.statusCode || 200,
|
|
3107
|
-
loaderHeaders: {},
|
|
3108
|
-
actionHeaders: result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
|
3109
|
-
};
|
|
3110
|
-
}
|
|
3111
|
-
}
|
|
3112
2926
|
let loaderRequest = new Request(request.url, {
|
|
3113
2927
|
headers: request.headers,
|
|
3114
2928
|
redirect: request.redirect,
|
|
@@ -3116,18 +2930,17 @@ function createStaticHandler(routes, opts) {
|
|
|
3116
2930
|
});
|
|
3117
2931
|
if (isErrorResult(result)) {
|
|
3118
2932
|
let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
|
|
3119
|
-
let
|
|
2933
|
+
let context2 = await loadRouteData(
|
|
3120
2934
|
loaderRequest,
|
|
3121
2935
|
matches,
|
|
3122
2936
|
requestContext,
|
|
3123
2937
|
dataStrategy,
|
|
3124
2938
|
skipLoaderErrorBubbling,
|
|
3125
2939
|
null,
|
|
3126
|
-
filterMatchesToLoad,
|
|
3127
2940
|
[boundaryMatch.route.id, result]
|
|
3128
2941
|
);
|
|
3129
2942
|
return {
|
|
3130
|
-
...
|
|
2943
|
+
...context2,
|
|
3131
2944
|
statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500,
|
|
3132
2945
|
actionData: null,
|
|
3133
2946
|
actionHeaders: {
|
|
@@ -3135,17 +2948,16 @@ function createStaticHandler(routes, opts) {
|
|
|
3135
2948
|
}
|
|
3136
2949
|
};
|
|
3137
2950
|
}
|
|
3138
|
-
let
|
|
2951
|
+
let context = await loadRouteData(
|
|
3139
2952
|
loaderRequest,
|
|
3140
2953
|
matches,
|
|
3141
2954
|
requestContext,
|
|
3142
2955
|
dataStrategy,
|
|
3143
2956
|
skipLoaderErrorBubbling,
|
|
3144
|
-
null
|
|
3145
|
-
filterMatchesToLoad
|
|
2957
|
+
null
|
|
3146
2958
|
);
|
|
3147
2959
|
return {
|
|
3148
|
-
...
|
|
2960
|
+
...context,
|
|
3149
2961
|
actionData: {
|
|
3150
2962
|
[actionMatch.route.id]: result.data
|
|
3151
2963
|
},
|
|
@@ -3154,7 +2966,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3154
2966
|
actionHeaders: result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
|
3155
2967
|
};
|
|
3156
2968
|
}
|
|
3157
|
-
async function loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch,
|
|
2969
|
+
async function loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, pendingActionResult) {
|
|
3158
2970
|
let isRouteRequest = routeMatch != null;
|
|
3159
2971
|
if (isRouteRequest && !routeMatch?.route.loader && !routeMatch?.route.lazy) {
|
|
3160
2972
|
throw getInternalRouterError(400, {
|
|
@@ -3165,7 +2977,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3165
2977
|
}
|
|
3166
2978
|
let requestMatches = routeMatch ? [routeMatch] : pendingActionResult && isErrorResult(pendingActionResult[1]) ? getLoaderMatchesUntilBoundary(matches, pendingActionResult[0]) : matches;
|
|
3167
2979
|
let matchesToLoad = requestMatches.filter(
|
|
3168
|
-
(m) =>
|
|
2980
|
+
(m) => m.route.loader || m.route.lazy
|
|
3169
2981
|
);
|
|
3170
2982
|
if (matchesToLoad.length === 0) {
|
|
3171
2983
|
return {
|
|
@@ -3182,7 +2994,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3182
2994
|
loaderHeaders: {}
|
|
3183
2995
|
};
|
|
3184
2996
|
}
|
|
3185
|
-
let results = await
|
|
2997
|
+
let results = await callDataStrategy(
|
|
3186
2998
|
"loader",
|
|
3187
2999
|
request,
|
|
3188
3000
|
matchesToLoad,
|
|
@@ -3194,7 +3006,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3194
3006
|
if (request.signal.aborted) {
|
|
3195
3007
|
throwStaticHandlerAbortedError(request, isRouteRequest);
|
|
3196
3008
|
}
|
|
3197
|
-
let
|
|
3009
|
+
let context = processRouteLoaderData(
|
|
3198
3010
|
matches,
|
|
3199
3011
|
results,
|
|
3200
3012
|
pendingActionResult,
|
|
@@ -3206,18 +3018,19 @@ function createStaticHandler(routes, opts) {
|
|
|
3206
3018
|
);
|
|
3207
3019
|
matches.forEach((match) => {
|
|
3208
3020
|
if (!executedLoaders.has(match.route.id)) {
|
|
3209
|
-
|
|
3021
|
+
context.loaderData[match.route.id] = null;
|
|
3210
3022
|
}
|
|
3211
3023
|
});
|
|
3212
3024
|
return {
|
|
3213
|
-
...
|
|
3025
|
+
...context,
|
|
3214
3026
|
matches
|
|
3215
3027
|
};
|
|
3216
3028
|
}
|
|
3217
|
-
async function
|
|
3029
|
+
async function callDataStrategy(type, request, matchesToLoad, matches, isRouteRequest, requestContext, dataStrategy) {
|
|
3218
3030
|
let results = await callDataStrategyImpl(
|
|
3219
3031
|
dataStrategy || defaultDataStrategy,
|
|
3220
3032
|
type,
|
|
3033
|
+
null,
|
|
3221
3034
|
request,
|
|
3222
3035
|
matchesToLoad,
|
|
3223
3036
|
matches,
|
|
@@ -3257,15 +3070,15 @@ function createStaticHandler(routes, opts) {
|
|
|
3257
3070
|
queryRoute
|
|
3258
3071
|
};
|
|
3259
3072
|
}
|
|
3260
|
-
function getStaticContextFromError(routes,
|
|
3261
|
-
let
|
|
3262
|
-
|
|
3263
|
-
...handlerContext,
|
|
3073
|
+
function getStaticContextFromError(routes, context, error) {
|
|
3074
|
+
let newContext = {
|
|
3075
|
+
...context,
|
|
3264
3076
|
statusCode: isRouteErrorResponse(error) ? error.status : 500,
|
|
3265
3077
|
errors: {
|
|
3266
|
-
[
|
|
3078
|
+
[context._deepestRenderedBoundaryId || routes[0].id]: error
|
|
3267
3079
|
}
|
|
3268
3080
|
};
|
|
3081
|
+
return newContext;
|
|
3269
3082
|
}
|
|
3270
3083
|
function throwStaticHandlerAbortedError(request, isRouteRequest) {
|
|
3271
3084
|
if (request.signal.reason !== void 0) {
|
|
@@ -3658,141 +3471,20 @@ async function loadLazyRouteModule(route, mapRouteProperties2, manifest) {
|
|
|
3658
3471
|
lazy: void 0
|
|
3659
3472
|
});
|
|
3660
3473
|
}
|
|
3661
|
-
async function
|
|
3662
|
-
|
|
3663
|
-
|
|
3474
|
+
async function defaultDataStrategy({
|
|
3475
|
+
matches
|
|
3476
|
+
}) {
|
|
3477
|
+
let matchesToLoad = matches.filter((m) => m.shouldLoad);
|
|
3664
3478
|
let results = await Promise.all(matchesToLoad.map((m) => m.resolve()));
|
|
3665
|
-
results.
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
return keyedResults;
|
|
3669
|
-
}
|
|
3670
|
-
async function defaultDataStrategy(args) {
|
|
3671
|
-
let matchesToLoad = args.matches.filter((m) => m.shouldLoad);
|
|
3672
|
-
let lastIndex = args.matches.length - 1;
|
|
3673
|
-
for (let i = lastIndex; i >= 0; i--) {
|
|
3674
|
-
if (args.matches[i].shouldLoad) {
|
|
3675
|
-
lastIndex = i;
|
|
3676
|
-
break;
|
|
3677
|
-
}
|
|
3678
|
-
}
|
|
3679
|
-
let results = await runMiddlewarePipeline(
|
|
3680
|
-
args,
|
|
3681
|
-
lastIndex,
|
|
3682
|
-
false,
|
|
3683
|
-
async (keyedResults) => {
|
|
3684
|
-
let results2 = await Promise.all(matchesToLoad.map((m) => m.resolve()));
|
|
3685
|
-
results2.forEach((result, i) => {
|
|
3686
|
-
keyedResults[matchesToLoad[i].route.id] = result;
|
|
3687
|
-
});
|
|
3688
|
-
},
|
|
3689
|
-
(e, keyedResults) => {
|
|
3690
|
-
Object.assign(keyedResults, {
|
|
3691
|
-
[e.routeId]: { type: "error", result: e.error }
|
|
3692
|
-
});
|
|
3693
|
-
}
|
|
3479
|
+
return results.reduce(
|
|
3480
|
+
(acc, result, i) => Object.assign(acc, { [matchesToLoad[i].route.id]: result }),
|
|
3481
|
+
{}
|
|
3694
3482
|
);
|
|
3695
|
-
return results;
|
|
3696
|
-
}
|
|
3697
|
-
async function runMiddlewarePipeline({
|
|
3698
|
-
request,
|
|
3699
|
-
params,
|
|
3700
|
-
context,
|
|
3701
|
-
matches
|
|
3702
|
-
}, lastIndex, propagateResult, handler, errorHandler) {
|
|
3703
|
-
let middlewareState = {
|
|
3704
|
-
keyedResults: {},
|
|
3705
|
-
propagateResult
|
|
3706
|
-
};
|
|
3707
|
-
try {
|
|
3708
|
-
let result = await callRouteMiddleware(
|
|
3709
|
-
matches.slice(0, lastIndex + 1).flatMap(
|
|
3710
|
-
(m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
|
|
3711
|
-
),
|
|
3712
|
-
0,
|
|
3713
|
-
{ request, params, context },
|
|
3714
|
-
middlewareState,
|
|
3715
|
-
handler
|
|
3716
|
-
);
|
|
3717
|
-
return middlewareState.propagateResult ? result : middlewareState.keyedResults;
|
|
3718
|
-
} catch (e) {
|
|
3719
|
-
if (!(e instanceof MiddlewareError)) {
|
|
3720
|
-
throw e;
|
|
3721
|
-
}
|
|
3722
|
-
if (propagateResult && isResponse(e.error)) {
|
|
3723
|
-
throw e.error;
|
|
3724
|
-
}
|
|
3725
|
-
let result = await errorHandler(e, middlewareState.keyedResults);
|
|
3726
|
-
return middlewareState.propagateResult ? result : middlewareState.keyedResults;
|
|
3727
|
-
}
|
|
3728
3483
|
}
|
|
3729
|
-
|
|
3730
|
-
constructor(routeId, error) {
|
|
3731
|
-
this.routeId = routeId;
|
|
3732
|
-
this.error = error;
|
|
3733
|
-
}
|
|
3734
|
-
};
|
|
3735
|
-
async function callRouteMiddleware(middlewares, idx, args, middlewareState, handler) {
|
|
3736
|
-
let { request } = args;
|
|
3737
|
-
if (request.signal.aborted) {
|
|
3738
|
-
if (request.signal.reason) {
|
|
3739
|
-
throw request.signal.reason;
|
|
3740
|
-
}
|
|
3741
|
-
throw new Error(
|
|
3742
|
-
`Request aborted without an \`AbortSignal.reason\`: ${request.method} ${request.url}`
|
|
3743
|
-
);
|
|
3744
|
-
}
|
|
3745
|
-
let tuple = middlewares[idx];
|
|
3746
|
-
if (!tuple) {
|
|
3747
|
-
let result = await handler(middlewareState.keyedResults);
|
|
3748
|
-
return result;
|
|
3749
|
-
}
|
|
3750
|
-
let [routeId, middleware] = tuple;
|
|
3751
|
-
let nextCalled = false;
|
|
3752
|
-
let next = async () => {
|
|
3753
|
-
if (nextCalled) {
|
|
3754
|
-
throw new Error("You may only call `next()` once per middleware");
|
|
3755
|
-
}
|
|
3756
|
-
nextCalled = true;
|
|
3757
|
-
let result = await callRouteMiddleware(
|
|
3758
|
-
middlewares,
|
|
3759
|
-
idx + 1,
|
|
3760
|
-
args,
|
|
3761
|
-
middlewareState,
|
|
3762
|
-
handler
|
|
3763
|
-
);
|
|
3764
|
-
if (middlewareState.propagateResult) {
|
|
3765
|
-
return result;
|
|
3766
|
-
}
|
|
3767
|
-
};
|
|
3768
|
-
try {
|
|
3769
|
-
let result = await middleware({
|
|
3770
|
-
request: args.request,
|
|
3771
|
-
params: args.params,
|
|
3772
|
-
context: args.context,
|
|
3773
|
-
next
|
|
3774
|
-
});
|
|
3775
|
-
return nextCalled ? result : next();
|
|
3776
|
-
} catch (e) {
|
|
3777
|
-
if (e instanceof MiddlewareError) {
|
|
3778
|
-
throw e;
|
|
3779
|
-
}
|
|
3780
|
-
throw new MiddlewareError(routeId, e);
|
|
3781
|
-
}
|
|
3782
|
-
}
|
|
3783
|
-
async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLoad, matches, fetcherKey, manifest, mapRouteProperties2, scopedContext) {
|
|
3484
|
+
async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matchesToLoad, matches, fetcherKey, manifest, mapRouteProperties2, requestContext) {
|
|
3784
3485
|
let loadRouteDefinitionsPromises = matches.map(
|
|
3785
3486
|
(m) => m.route.lazy ? loadLazyRouteModule(m.route, mapRouteProperties2, manifest) : void 0
|
|
3786
3487
|
);
|
|
3787
|
-
let lazyMiddlewarePromises = matches.map(
|
|
3788
|
-
(m, i) => m.route.lazy && !("middleware" in m.route) ? (
|
|
3789
|
-
// Swallow the error here, let it bubble up from resolve()
|
|
3790
|
-
loadRouteDefinitionsPromises[i].catch((e) => e)
|
|
3791
|
-
) : null
|
|
3792
|
-
).filter((p) => p != null);
|
|
3793
|
-
if (lazyMiddlewarePromises.length > 0) {
|
|
3794
|
-
await Promise.all(lazyMiddlewarePromises);
|
|
3795
|
-
}
|
|
3796
3488
|
let dsMatches = matches.map((match, i) => {
|
|
3797
3489
|
let loadRoutePromise = loadRouteDefinitionsPromises[i];
|
|
3798
3490
|
let shouldLoad = matchesToLoad.some((m) => m.route.id === match.route.id);
|
|
@@ -3806,7 +3498,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
|
|
|
3806
3498
|
match,
|
|
3807
3499
|
loadRoutePromise,
|
|
3808
3500
|
handlerOverride,
|
|
3809
|
-
|
|
3501
|
+
requestContext
|
|
3810
3502
|
) : Promise.resolve({ type: "data" /* data */, result: void 0 });
|
|
3811
3503
|
};
|
|
3812
3504
|
return {
|
|
@@ -3820,7 +3512,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
|
|
|
3820
3512
|
request,
|
|
3821
3513
|
params: matches[0].params,
|
|
3822
3514
|
fetcherKey,
|
|
3823
|
-
context:
|
|
3515
|
+
context: requestContext
|
|
3824
3516
|
});
|
|
3825
3517
|
try {
|
|
3826
3518
|
await Promise.all(loadRouteDefinitionsPromises);
|
|
@@ -3828,7 +3520,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
|
|
|
3828
3520
|
}
|
|
3829
3521
|
return results;
|
|
3830
3522
|
}
|
|
3831
|
-
async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride,
|
|
3523
|
+
async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride, staticContext) {
|
|
3832
3524
|
let result;
|
|
3833
3525
|
let onReject;
|
|
3834
3526
|
let runHandler = (handler) => {
|
|
@@ -3848,7 +3540,7 @@ async function callLoaderOrAction(type, request, match, loadRoutePromise, handle
|
|
|
3848
3540
|
{
|
|
3849
3541
|
request,
|
|
3850
3542
|
params: match.params,
|
|
3851
|
-
context:
|
|
3543
|
+
context: staticContext
|
|
3852
3544
|
},
|
|
3853
3545
|
...ctx !== void 0 ? [ctx] : []
|
|
3854
3546
|
);
|
|
@@ -3955,14 +3647,20 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
|
|
|
3955
3647
|
return {
|
|
3956
3648
|
type: "error" /* error */,
|
|
3957
3649
|
error: result.data,
|
|
3958
|
-
statusCode: result.init?.status
|
|
3650
|
+
statusCode: result.init?.status,
|
|
3651
|
+
headers: result.init?.headers ? new Headers(result.init.headers) : void 0
|
|
3959
3652
|
};
|
|
3960
3653
|
}
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3654
|
+
return {
|
|
3655
|
+
type: "error" /* error */,
|
|
3656
|
+
error: new ErrorResponseImpl(
|
|
3657
|
+
result.init?.status || 500,
|
|
3658
|
+
void 0,
|
|
3659
|
+
result.data
|
|
3660
|
+
),
|
|
3661
|
+
statusCode: isRouteErrorResponse(result) ? result.status : void 0,
|
|
3662
|
+
headers: result.init?.headers ? new Headers(result.init.headers) : void 0
|
|
3663
|
+
};
|
|
3966
3664
|
}
|
|
3967
3665
|
return {
|
|
3968
3666
|
type: "error" /* error */,
|
|
@@ -4699,7 +4397,7 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
|
|
|
4699
4397
|
let segments = pathname.replace(/^\//, "").split("/");
|
|
4700
4398
|
remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
|
|
4701
4399
|
}
|
|
4702
|
-
let matches = matchRoutes(routes, { pathname: remainingPathname });
|
|
4400
|
+
let matches = dataRouterState && dataRouterState.matches && dataRouterState.matches.length > 0 ? dataRouterState.matches : matchRoutes(routes, { pathname: remainingPathname });
|
|
4703
4401
|
if (ENABLE_DEV_WARNINGS) {
|
|
4704
4402
|
warning(
|
|
4705
4403
|
parentRoute || matches != null,
|
|
@@ -5155,7 +4853,6 @@ function mapRouteProperties(route) {
|
|
|
5155
4853
|
function createMemoryRouter(routes, opts) {
|
|
5156
4854
|
return createRouter({
|
|
5157
4855
|
basename: opts?.basename,
|
|
5158
|
-
context: opts?.context,
|
|
5159
4856
|
future: opts?.future,
|
|
5160
4857
|
history: createMemoryHistory({
|
|
5161
4858
|
initialEntries: opts?.initialEntries,
|
|
@@ -5807,7 +5504,7 @@ function getKeyedLinksForMatches(matches, routeModules, manifest) {
|
|
|
5807
5504
|
module2?.links?.() || []
|
|
5808
5505
|
];
|
|
5809
5506
|
}).flat(2);
|
|
5810
|
-
let preloads =
|
|
5507
|
+
let preloads = getModuleLinkHrefs(matches, manifest);
|
|
5811
5508
|
return dedupeLinkDescriptors(descriptors, preloads);
|
|
5812
5509
|
}
|
|
5813
5510
|
async function prefetchStyleLinks(route, routeModule) {
|
|
@@ -5931,25 +5628,21 @@ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, loca
|
|
|
5931
5628
|
}
|
|
5932
5629
|
return [];
|
|
5933
5630
|
}
|
|
5934
|
-
function getModuleLinkHrefs(matches,
|
|
5935
|
-
return dedupeHrefs(
|
|
5936
|
-
matches.map((match) => {
|
|
5937
|
-
let route = manifestPatch.routes[match.route.id];
|
|
5938
|
-
if (!route) return [];
|
|
5939
|
-
let hrefs = [route.module];
|
|
5940
|
-
if (route.imports) {
|
|
5941
|
-
hrefs = hrefs.concat(route.imports);
|
|
5942
|
-
}
|
|
5943
|
-
return hrefs;
|
|
5944
|
-
}).flat(1)
|
|
5945
|
-
);
|
|
5946
|
-
}
|
|
5947
|
-
function getCurrentPageModulePreloadHrefs(matches, manifest) {
|
|
5631
|
+
function getModuleLinkHrefs(matches, manifest, { includeHydrateFallback } = {}) {
|
|
5948
5632
|
return dedupeHrefs(
|
|
5949
5633
|
matches.map((match) => {
|
|
5950
5634
|
let route = manifest.routes[match.route.id];
|
|
5951
5635
|
if (!route) return [];
|
|
5952
5636
|
let hrefs = [route.module];
|
|
5637
|
+
if (route.clientActionModule) {
|
|
5638
|
+
hrefs = hrefs.concat(route.clientActionModule);
|
|
5639
|
+
}
|
|
5640
|
+
if (route.clientLoaderModule) {
|
|
5641
|
+
hrefs = hrefs.concat(route.clientLoaderModule);
|
|
5642
|
+
}
|
|
5643
|
+
if (includeHydrateFallback && route.hydrateFallbackModule) {
|
|
5644
|
+
hrefs = hrefs.concat(route.hydrateFallbackModule);
|
|
5645
|
+
}
|
|
5953
5646
|
if (route.imports) {
|
|
5954
5647
|
hrefs = hrefs.concat(route.imports);
|
|
5955
5648
|
}
|
|
@@ -6104,63 +5797,21 @@ function StreamTransfer({
|
|
|
6104
5797
|
)));
|
|
6105
5798
|
}
|
|
6106
5799
|
}
|
|
6107
|
-
function middlewareErrorHandler(e, keyedResults) {
|
|
6108
|
-
Object.assign(keyedResults, {
|
|
6109
|
-
[e.routeId]: { type: "error", result: e.error }
|
|
6110
|
-
});
|
|
6111
|
-
}
|
|
6112
5800
|
function getSingleFetchDataStrategy(manifest, routeModules, getRouter) {
|
|
6113
|
-
return async (
|
|
6114
|
-
let { request, matches, fetcherKey } = args;
|
|
5801
|
+
return async ({ request, matches, fetcherKey }) => {
|
|
6115
5802
|
if (request.method !== "GET") {
|
|
6116
|
-
return
|
|
6117
|
-
args,
|
|
6118
|
-
matches.findIndex((m) => m.shouldLoad),
|
|
6119
|
-
false,
|
|
6120
|
-
async (keyedResults) => {
|
|
6121
|
-
let results = await singleFetchActionStrategy(request, matches);
|
|
6122
|
-
Object.assign(keyedResults, results);
|
|
6123
|
-
},
|
|
6124
|
-
middlewareErrorHandler
|
|
6125
|
-
);
|
|
5803
|
+
return singleFetchActionStrategy(request, matches);
|
|
6126
5804
|
}
|
|
6127
5805
|
if (fetcherKey) {
|
|
6128
|
-
return
|
|
6129
|
-
args,
|
|
6130
|
-
matches.findIndex((m) => m.shouldLoad),
|
|
6131
|
-
false,
|
|
6132
|
-
async (keyedResults) => {
|
|
6133
|
-
let results = await singleFetchLoaderFetcherStrategy(
|
|
6134
|
-
request,
|
|
6135
|
-
matches
|
|
6136
|
-
);
|
|
6137
|
-
Object.assign(keyedResults, results);
|
|
6138
|
-
},
|
|
6139
|
-
middlewareErrorHandler
|
|
6140
|
-
);
|
|
5806
|
+
return singleFetchLoaderFetcherStrategy(request, matches);
|
|
6141
5807
|
}
|
|
6142
|
-
|
|
5808
|
+
return singleFetchLoaderNavigationStrategy(
|
|
6143
5809
|
manifest,
|
|
6144
5810
|
routeModules,
|
|
6145
5811
|
getRouter(),
|
|
5812
|
+
request,
|
|
6146
5813
|
matches
|
|
6147
5814
|
);
|
|
6148
|
-
return runMiddlewarePipeline(
|
|
6149
|
-
args,
|
|
6150
|
-
lowestLoadingIndex,
|
|
6151
|
-
false,
|
|
6152
|
-
async (keyedResults) => {
|
|
6153
|
-
let results = await singleFetchLoaderNavigationStrategy(
|
|
6154
|
-
manifest,
|
|
6155
|
-
routeModules,
|
|
6156
|
-
getRouter(),
|
|
6157
|
-
request,
|
|
6158
|
-
matches
|
|
6159
|
-
);
|
|
6160
|
-
Object.assign(keyedResults, results);
|
|
6161
|
-
},
|
|
6162
|
-
middlewareErrorHandler
|
|
6163
|
-
);
|
|
6164
5815
|
};
|
|
6165
5816
|
}
|
|
6166
5817
|
async function singleFetchActionStrategy(request, matches) {
|
|
@@ -6190,20 +5841,6 @@ async function singleFetchActionStrategy(request, matches) {
|
|
|
6190
5841
|
}
|
|
6191
5842
|
};
|
|
6192
5843
|
}
|
|
6193
|
-
function isOptedOut(manifestRoute, routeModule, match, router) {
|
|
6194
|
-
return match.route.id in router.state.loaderData && manifestRoute && manifestRoute.hasLoader && routeModule && routeModule.shouldRevalidate;
|
|
6195
|
-
}
|
|
6196
|
-
function getLowestLoadingIndex(manifest, routeModules, router, matches) {
|
|
6197
|
-
let tailIdx = [...matches].reverse().findIndex(
|
|
6198
|
-
(m) => m.shouldLoad || !isOptedOut(
|
|
6199
|
-
manifest.routes[m.route.id],
|
|
6200
|
-
routeModules[m.route.id],
|
|
6201
|
-
m,
|
|
6202
|
-
router
|
|
6203
|
-
)
|
|
6204
|
-
);
|
|
6205
|
-
return tailIdx < 0 ? 0 : matches.length - 1 - tailIdx;
|
|
6206
|
-
}
|
|
6207
5844
|
async function singleFetchLoaderNavigationStrategy(manifest, routeModules, router, request, matches) {
|
|
6208
5845
|
let routesParams = /* @__PURE__ */ new Set();
|
|
6209
5846
|
let foundOptOutRoute = false;
|
|
@@ -6222,7 +5859,7 @@ async function singleFetchLoaderNavigationStrategy(manifest, routeModules, route
|
|
|
6222
5859
|
if (!router.state.initialized) {
|
|
6223
5860
|
return;
|
|
6224
5861
|
}
|
|
6225
|
-
if (
|
|
5862
|
+
if (m.route.id in router.state.loaderData && manifestRoute && manifestRoute.hasLoader && routeModules[m.route.id]?.shouldRevalidate) {
|
|
6226
5863
|
foundOptOutRoute = true;
|
|
6227
5864
|
return;
|
|
6228
5865
|
}
|
|
@@ -6622,8 +6259,8 @@ function createServerRoutes(manifest, routeModules, future, isSpaMode, parentId
|
|
|
6622
6259
|
// render, so just give it a no-op function so we can render down to the
|
|
6623
6260
|
// proper fallback
|
|
6624
6261
|
loader: route.hasLoader || route.hasClientLoader ? () => null : void 0
|
|
6625
|
-
// We don't need
|
|
6626
|
-
//
|
|
6262
|
+
// We don't need action/shouldRevalidate on these routes since they're
|
|
6263
|
+
// for a static render
|
|
6627
6264
|
};
|
|
6628
6265
|
let children = createServerRoutes(
|
|
6629
6266
|
manifest,
|
|
@@ -6689,6 +6326,21 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6689
6326
|
}
|
|
6690
6327
|
return fetchServerHandler(singleFetch);
|
|
6691
6328
|
}
|
|
6329
|
+
function prefetchModule(modulePath) {
|
|
6330
|
+
import(
|
|
6331
|
+
/* @vite-ignore */
|
|
6332
|
+
/* webpackIgnore: true */
|
|
6333
|
+
modulePath
|
|
6334
|
+
);
|
|
6335
|
+
}
|
|
6336
|
+
function prefetchRouteModuleChunks(route2) {
|
|
6337
|
+
if (route2.clientActionModule) {
|
|
6338
|
+
prefetchModule(route2.clientActionModule);
|
|
6339
|
+
}
|
|
6340
|
+
if (route2.clientLoaderModule) {
|
|
6341
|
+
prefetchModule(route2.clientLoaderModule);
|
|
6342
|
+
}
|
|
6343
|
+
}
|
|
6692
6344
|
async function prefetchStylesAndCallHandler(handler) {
|
|
6693
6345
|
let cachedModule = routeModulesCache[route.id];
|
|
6694
6346
|
let linkPrefetchPromise = cachedModule ? prefetchStyleLinks(route, cachedModule) : Promise.resolve();
|
|
@@ -6707,7 +6359,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6707
6359
|
Object.assign(dataRoute, {
|
|
6708
6360
|
...dataRoute,
|
|
6709
6361
|
...getRouteComponents(route, routeModule, isSpaMode),
|
|
6710
|
-
middleware: routeModule.clientMiddleware,
|
|
6711
6362
|
handle: routeModule.handle,
|
|
6712
6363
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
6713
6364
|
routeModule,
|
|
@@ -6720,7 +6371,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6720
6371
|
let hasInitialError = initialState && initialState.errors && route.id in initialState.errors;
|
|
6721
6372
|
let initialError = hasInitialError ? initialState?.errors?.[route.id] : void 0;
|
|
6722
6373
|
let isHydrationRequest = needsRevalidation == null && (routeModule.clientLoader?.hydrate === true || !route.hasLoader);
|
|
6723
|
-
dataRoute.loader = async ({ request, params
|
|
6374
|
+
dataRoute.loader = async ({ request, params }, singleFetch) => {
|
|
6724
6375
|
try {
|
|
6725
6376
|
let result = await prefetchStylesAndCallHandler(async () => {
|
|
6726
6377
|
invariant2(
|
|
@@ -6734,7 +6385,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6734
6385
|
return routeModule.clientLoader({
|
|
6735
6386
|
request,
|
|
6736
6387
|
params,
|
|
6737
|
-
context,
|
|
6738
6388
|
async serverLoader() {
|
|
6739
6389
|
preventInvalidServerHandlerCall("loader", route, isSpaMode);
|
|
6740
6390
|
if (isHydrationRequest) {
|
|
@@ -6759,7 +6409,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6759
6409
|
routeModule,
|
|
6760
6410
|
isSpaMode
|
|
6761
6411
|
);
|
|
6762
|
-
dataRoute.action = ({ request, params
|
|
6412
|
+
dataRoute.action = ({ request, params }, singleFetch) => {
|
|
6763
6413
|
return prefetchStylesAndCallHandler(async () => {
|
|
6764
6414
|
invariant2(
|
|
6765
6415
|
routeModule,
|
|
@@ -6774,7 +6424,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6774
6424
|
return routeModule.clientAction({
|
|
6775
6425
|
request,
|
|
6776
6426
|
params,
|
|
6777
|
-
context,
|
|
6778
6427
|
async serverAction() {
|
|
6779
6428
|
preventInvalidServerHandlerCall("action", route, isSpaMode);
|
|
6780
6429
|
return fetchServerAction(singleFetch);
|
|
@@ -6784,26 +6433,64 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6784
6433
|
};
|
|
6785
6434
|
} else {
|
|
6786
6435
|
if (!route.hasClientLoader) {
|
|
6787
|
-
dataRoute.loader = (
|
|
6436
|
+
dataRoute.loader = ({ request }, singleFetch) => prefetchStylesAndCallHandler(() => {
|
|
6788
6437
|
if (isSpaMode) return Promise.resolve(null);
|
|
6789
6438
|
return fetchServerLoader(singleFetch);
|
|
6790
6439
|
});
|
|
6440
|
+
} else if (route.clientLoaderModule) {
|
|
6441
|
+
dataRoute.loader = async (args, singleFetch) => {
|
|
6442
|
+
invariant2(route.clientLoaderModule);
|
|
6443
|
+
let { clientLoader } = await import(
|
|
6444
|
+
/* @vite-ignore */
|
|
6445
|
+
/* webpackIgnore: true */
|
|
6446
|
+
route.clientLoaderModule
|
|
6447
|
+
);
|
|
6448
|
+
return clientLoader({
|
|
6449
|
+
...args,
|
|
6450
|
+
async serverLoader() {
|
|
6451
|
+
preventInvalidServerHandlerCall("loader", route, isSpaMode);
|
|
6452
|
+
return fetchServerLoader(singleFetch);
|
|
6453
|
+
}
|
|
6454
|
+
});
|
|
6455
|
+
};
|
|
6791
6456
|
}
|
|
6792
6457
|
if (!route.hasClientAction) {
|
|
6793
|
-
dataRoute.action = (
|
|
6458
|
+
dataRoute.action = ({ request }, singleFetch) => prefetchStylesAndCallHandler(() => {
|
|
6794
6459
|
if (isSpaMode) {
|
|
6795
6460
|
throw noActionDefinedError("clientAction", route.id);
|
|
6796
6461
|
}
|
|
6797
6462
|
return fetchServerAction(singleFetch);
|
|
6798
6463
|
});
|
|
6464
|
+
} else if (route.clientActionModule) {
|
|
6465
|
+
dataRoute.action = async (args, singleFetch) => {
|
|
6466
|
+
invariant2(route.clientActionModule);
|
|
6467
|
+
prefetchRouteModuleChunks(route);
|
|
6468
|
+
let { clientAction } = await import(
|
|
6469
|
+
/* @vite-ignore */
|
|
6470
|
+
/* webpackIgnore: true */
|
|
6471
|
+
route.clientActionModule
|
|
6472
|
+
);
|
|
6473
|
+
return clientAction({
|
|
6474
|
+
...args,
|
|
6475
|
+
async serverAction() {
|
|
6476
|
+
preventInvalidServerHandlerCall("action", route, isSpaMode);
|
|
6477
|
+
return fetchServerAction(singleFetch);
|
|
6478
|
+
}
|
|
6479
|
+
});
|
|
6480
|
+
};
|
|
6799
6481
|
}
|
|
6800
6482
|
dataRoute.lazy = async () => {
|
|
6801
|
-
|
|
6483
|
+
if (route.clientLoaderModule || route.clientActionModule) {
|
|
6484
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
6485
|
+
}
|
|
6486
|
+
let modPromise = loadRouteModuleWithBlockingLinks(
|
|
6802
6487
|
route,
|
|
6803
6488
|
routeModulesCache
|
|
6804
6489
|
);
|
|
6490
|
+
prefetchRouteModuleChunks(route);
|
|
6491
|
+
let mod = await modPromise;
|
|
6805
6492
|
let lazyRoute = { ...mod };
|
|
6806
|
-
if (mod.clientLoader) {
|
|
6493
|
+
if (mod.clientLoader && !route.clientLoaderModule) {
|
|
6807
6494
|
let clientLoader = mod.clientLoader;
|
|
6808
6495
|
lazyRoute.loader = (args, singleFetch) => clientLoader({
|
|
6809
6496
|
...args,
|
|
@@ -6813,7 +6500,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6813
6500
|
}
|
|
6814
6501
|
});
|
|
6815
6502
|
}
|
|
6816
|
-
if (mod.clientAction) {
|
|
6503
|
+
if (mod.clientAction && !route.clientActionModule) {
|
|
6817
6504
|
let clientAction = mod.clientAction;
|
|
6818
6505
|
lazyRoute.action = (args, singleFetch) => clientAction({
|
|
6819
6506
|
...args,
|
|
@@ -6826,7 +6513,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6826
6513
|
return {
|
|
6827
6514
|
...lazyRoute.loader ? { loader: lazyRoute.loader } : {},
|
|
6828
6515
|
...lazyRoute.action ? { action: lazyRoute.action } : {},
|
|
6829
|
-
middleware: mod.clientMiddleware,
|
|
6830
6516
|
hasErrorBoundary: lazyRoute.hasErrorBoundary,
|
|
6831
6517
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
6832
6518
|
lazyRoute,
|
|
@@ -6884,7 +6570,6 @@ async function loadRouteModuleWithBlockingLinks(route, routeModules) {
|
|
|
6884
6570
|
return {
|
|
6885
6571
|
Component: getRouteModuleComponent(routeModule),
|
|
6886
6572
|
ErrorBoundary: routeModule.ErrorBoundary,
|
|
6887
|
-
clientMiddleware: routeModule.clientMiddleware,
|
|
6888
6573
|
clientAction: routeModule.clientAction,
|
|
6889
6574
|
clientLoader: routeModule.clientLoader,
|
|
6890
6575
|
handle: routeModule.handle,
|
|
@@ -7407,11 +7092,44 @@ function Scripts(props) {
|
|
|
7407
7092
|
let streamScript = "window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());";
|
|
7408
7093
|
let contextScript = staticContext ? `window.__reactRouterContext = ${serverHandoffString};${streamScript}` : " ";
|
|
7409
7094
|
let routeModulesScript = !isStatic ? " " : `${manifest.hmr?.runtime ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
|
|
7410
|
-
${matches.map(
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
)
|
|
7414
|
-
|
|
7095
|
+
${matches.map((match, routeIndex) => {
|
|
7096
|
+
let routeVarName = `route${routeIndex}`;
|
|
7097
|
+
let manifestEntry = manifest.routes[match.route.id];
|
|
7098
|
+
invariant2(manifestEntry, `Route ${match.route.id} not found in manifest`);
|
|
7099
|
+
let {
|
|
7100
|
+
clientActionModule,
|
|
7101
|
+
clientLoaderModule,
|
|
7102
|
+
hydrateFallbackModule,
|
|
7103
|
+
module: module2
|
|
7104
|
+
} = manifestEntry;
|
|
7105
|
+
let chunks = [
|
|
7106
|
+
...clientActionModule ? [
|
|
7107
|
+
{
|
|
7108
|
+
module: clientActionModule,
|
|
7109
|
+
varName: `${routeVarName}_clientAction`
|
|
7110
|
+
}
|
|
7111
|
+
] : [],
|
|
7112
|
+
...clientLoaderModule ? [
|
|
7113
|
+
{
|
|
7114
|
+
module: clientLoaderModule,
|
|
7115
|
+
varName: `${routeVarName}_clientLoader`
|
|
7116
|
+
}
|
|
7117
|
+
] : [],
|
|
7118
|
+
...hydrateFallbackModule ? [
|
|
7119
|
+
{
|
|
7120
|
+
module: hydrateFallbackModule,
|
|
7121
|
+
varName: `${routeVarName}_HydrateFallback`
|
|
7122
|
+
}
|
|
7123
|
+
] : [],
|
|
7124
|
+
{ module: module2, varName: `${routeVarName}_main` }
|
|
7125
|
+
];
|
|
7126
|
+
if (chunks.length === 1) {
|
|
7127
|
+
return `import * as ${routeVarName} from ${JSON.stringify(module2)};`;
|
|
7128
|
+
}
|
|
7129
|
+
let chunkImportsSnippet = chunks.map((chunk) => `import * as ${chunk.varName} from "${chunk.module}";`).join("\n");
|
|
7130
|
+
let mergedChunksSnippet = `const ${routeVarName} = {${chunks.map((chunk) => `...${chunk.varName}`).join(",")}};`;
|
|
7131
|
+
return [chunkImportsSnippet, mergedChunksSnippet].join("\n");
|
|
7132
|
+
}).join("\n")}
|
|
7415
7133
|
${enableFogOfWar ? (
|
|
7416
7134
|
// Inline a minimal manifest with the SSR matches
|
|
7417
7135
|
`window.__reactRouterManifest = ${JSON.stringify(
|
|
@@ -7442,11 +7160,11 @@ import(${JSON.stringify(manifest.entry.module)});`;
|
|
|
7442
7160
|
}
|
|
7443
7161
|
));
|
|
7444
7162
|
}, []);
|
|
7445
|
-
let
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
7163
|
+
let preloads = isHydrated ? [] : manifest.entry.imports.concat(
|
|
7164
|
+
getModuleLinkHrefs(matches, manifest, {
|
|
7165
|
+
includeHydrateFallback: true
|
|
7166
|
+
})
|
|
7167
|
+
);
|
|
7450
7168
|
return isHydrated ? null : /* @__PURE__ */ React9.createElement(React9.Fragment, null, !enableFogOfWar ? /* @__PURE__ */ React9.createElement(
|
|
7451
7169
|
"link",
|
|
7452
7170
|
{
|
|
@@ -7490,14 +7208,13 @@ function mergeRefs(...refs) {
|
|
|
7490
7208
|
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
7491
7209
|
try {
|
|
7492
7210
|
if (isBrowser) {
|
|
7493
|
-
window.__reactRouterVersion = "0.0.0-experimental-
|
|
7211
|
+
window.__reactRouterVersion = "0.0.0-experimental-df0f1dfda";
|
|
7494
7212
|
}
|
|
7495
7213
|
} catch (e) {
|
|
7496
7214
|
}
|
|
7497
7215
|
function createBrowserRouter(routes, opts) {
|
|
7498
7216
|
return createRouter({
|
|
7499
7217
|
basename: opts?.basename,
|
|
7500
|
-
context: opts?.context,
|
|
7501
7218
|
future: opts?.future,
|
|
7502
7219
|
history: createBrowserHistory({ window: opts?.window }),
|
|
7503
7220
|
hydrationData: opts?.hydrationData || parseHydrationData(),
|
|
@@ -7511,7 +7228,6 @@ function createBrowserRouter(routes, opts) {
|
|
|
7511
7228
|
function createHashRouter(routes, opts) {
|
|
7512
7229
|
return createRouter({
|
|
7513
7230
|
basename: opts?.basename,
|
|
7514
|
-
context: opts?.context,
|
|
7515
7231
|
future: opts?.future,
|
|
7516
7232
|
history: createHashHistory({ window: opts?.window }),
|
|
7517
7233
|
hydrationData: opts?.hydrationData || parseHydrationData(),
|
|
@@ -8653,14 +8369,13 @@ function createRoutesStub(routes, context = {}) {
|
|
|
8653
8369
|
isSpaMode: false
|
|
8654
8370
|
};
|
|
8655
8371
|
let patched = processRoutes(
|
|
8656
|
-
// @ts-expect-error
|
|
8657
|
-
// types compared to `AgnosticRouteObject`
|
|
8372
|
+
// @ts-expect-error loader/action context types don't match :/
|
|
8658
8373
|
convertRoutesToDataRoutes(routes, (r) => r),
|
|
8374
|
+
context,
|
|
8659
8375
|
remixContextRef.current.manifest,
|
|
8660
8376
|
remixContextRef.current.routeModules
|
|
8661
8377
|
);
|
|
8662
8378
|
routerRef.current = createMemoryRouter(patched, {
|
|
8663
|
-
context,
|
|
8664
8379
|
initialEntries,
|
|
8665
8380
|
initialIndex,
|
|
8666
8381
|
hydrationData
|
|
@@ -8669,13 +8384,14 @@ function createRoutesStub(routes, context = {}) {
|
|
|
8669
8384
|
return /* @__PURE__ */ React13.createElement(FrameworkContext.Provider, { value: remixContextRef.current }, /* @__PURE__ */ React13.createElement(RouterProvider, { router: routerRef.current }));
|
|
8670
8385
|
};
|
|
8671
8386
|
}
|
|
8672
|
-
function processRoutes(routes, manifest, routeModules, parentId) {
|
|
8387
|
+
function processRoutes(routes, context, manifest, routeModules, parentId) {
|
|
8673
8388
|
return routes.map((route) => {
|
|
8674
8389
|
if (!route.id) {
|
|
8675
8390
|
throw new Error(
|
|
8676
8391
|
"Expected a route.id in @remix-run/testing processRoutes() function"
|
|
8677
8392
|
);
|
|
8678
8393
|
}
|
|
8394
|
+
let { loader, action } = route;
|
|
8679
8395
|
let newRoute = {
|
|
8680
8396
|
id: route.id,
|
|
8681
8397
|
path: route.path,
|
|
@@ -8683,8 +8399,8 @@ function processRoutes(routes, manifest, routeModules, parentId) {
|
|
|
8683
8399
|
Component: route.Component,
|
|
8684
8400
|
HydrateFallback: route.HydrateFallback,
|
|
8685
8401
|
ErrorBoundary: route.ErrorBoundary,
|
|
8686
|
-
action:
|
|
8687
|
-
loader:
|
|
8402
|
+
action: action ? (args) => action({ ...args, context }) : void 0,
|
|
8403
|
+
loader: loader ? (args) => loader({ ...args, context }) : void 0,
|
|
8688
8404
|
handle: route.handle,
|
|
8689
8405
|
shouldRevalidate: route.shouldRevalidate
|
|
8690
8406
|
};
|
|
@@ -8701,8 +8417,11 @@ function processRoutes(routes, manifest, routeModules, parentId) {
|
|
|
8701
8417
|
hasClientAction: false,
|
|
8702
8418
|
hasClientLoader: false,
|
|
8703
8419
|
hasErrorBoundary: route.ErrorBoundary != null,
|
|
8704
|
-
|
|
8705
|
-
|
|
8420
|
+
// any need for these?
|
|
8421
|
+
module: "build/stub-path-to-module.js",
|
|
8422
|
+
clientActionModule: void 0,
|
|
8423
|
+
clientLoaderModule: void 0,
|
|
8424
|
+
hydrateFallbackModule: void 0
|
|
8706
8425
|
};
|
|
8707
8426
|
manifest.routes[newRoute.id] = entryRoute;
|
|
8708
8427
|
routeModules[route.id] = {
|
|
@@ -8716,6 +8435,7 @@ function processRoutes(routes, manifest, routeModules, parentId) {
|
|
|
8716
8435
|
if (route.children) {
|
|
8717
8436
|
newRoute.children = processRoutes(
|
|
8718
8437
|
route.children,
|
|
8438
|
+
context,
|
|
8719
8439
|
manifest,
|
|
8720
8440
|
routeModules,
|
|
8721
8441
|
newRoute.id
|
|
@@ -9076,7 +8796,6 @@ function createStaticHandlerDataRoutes(manifest, future, parentId = "", routesBy
|
|
|
9076
8796
|
hasErrorBoundary: route.id === "root" || route.module.ErrorBoundary != null,
|
|
9077
8797
|
id: route.id,
|
|
9078
8798
|
path: route.path,
|
|
9079
|
-
middleware: route.module.middleware,
|
|
9080
8799
|
// Need to use RR's version in the param typed here to permit the optional
|
|
9081
8800
|
// context even though we know it'll always be provided in remix
|
|
9082
8801
|
loader: route.module.loader ? async (args) => {
|
|
@@ -9212,15 +8931,35 @@ function prependCookies(parentHeaders, childHeaders) {
|
|
|
9212
8931
|
let parentSetCookieString = parentHeaders.get("Set-Cookie");
|
|
9213
8932
|
if (parentSetCookieString) {
|
|
9214
8933
|
let cookies = (0, import_set_cookie_parser.splitCookiesString)(parentSetCookieString);
|
|
8934
|
+
let childCookies = new Set(childHeaders.getSetCookie());
|
|
9215
8935
|
cookies.forEach((cookie) => {
|
|
9216
|
-
|
|
8936
|
+
if (!childCookies.has(cookie)) {
|
|
8937
|
+
childHeaders.append("Set-Cookie", cookie);
|
|
8938
|
+
}
|
|
9217
8939
|
});
|
|
9218
8940
|
}
|
|
9219
8941
|
}
|
|
9220
8942
|
|
|
9221
8943
|
// lib/server-runtime/single-fetch.ts
|
|
9222
|
-
var NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([100, 101, 204, 205, 304]);
|
|
9223
8944
|
var SINGLE_FETCH_REDIRECT_STATUS = 202;
|
|
8945
|
+
function getSingleFetchDataStrategy2({
|
|
8946
|
+
isActionDataRequest,
|
|
8947
|
+
loadRouteIds
|
|
8948
|
+
} = {}) {
|
|
8949
|
+
return async ({ request, matches }) => {
|
|
8950
|
+
if (isActionDataRequest && request.method === "GET") {
|
|
8951
|
+
return {};
|
|
8952
|
+
}
|
|
8953
|
+
let matchesToLoad = loadRouteIds ? matches.filter((m) => loadRouteIds.includes(m.route.id)) : matches;
|
|
8954
|
+
let results = await Promise.all(
|
|
8955
|
+
matchesToLoad.map((match) => match.resolve())
|
|
8956
|
+
);
|
|
8957
|
+
return results.reduce(
|
|
8958
|
+
(acc, result, i) => Object.assign(acc, { [matchesToLoad[i].route.id]: result }),
|
|
8959
|
+
{}
|
|
8960
|
+
);
|
|
8961
|
+
};
|
|
8962
|
+
}
|
|
9224
8963
|
async function singleFetchAction(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
|
|
9225
8964
|
try {
|
|
9226
8965
|
let handlerRequest = new Request(handlerUrl, {
|
|
@@ -9233,46 +8972,12 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
|
|
|
9233
8972
|
let result = await staticHandler.query(handlerRequest, {
|
|
9234
8973
|
requestContext: loadContext,
|
|
9235
8974
|
skipLoaderErrorBubbling: true,
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
9240
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
9241
|
-
result: getSingleFetchRedirect(
|
|
9242
|
-
context.statusCode,
|
|
9243
|
-
headers,
|
|
9244
|
-
build.basename
|
|
9245
|
-
),
|
|
9246
|
-
headers,
|
|
9247
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
9248
|
-
});
|
|
9249
|
-
}
|
|
9250
|
-
if (context.errors) {
|
|
9251
|
-
Object.values(context.errors).forEach((err) => {
|
|
9252
|
-
if (!isRouteErrorResponse(err) || err.error) {
|
|
9253
|
-
handleError(err);
|
|
9254
|
-
}
|
|
9255
|
-
});
|
|
9256
|
-
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9257
|
-
}
|
|
9258
|
-
let singleFetchResult;
|
|
9259
|
-
if (context.errors) {
|
|
9260
|
-
singleFetchResult = { error: Object.values(context.errors)[0] };
|
|
9261
|
-
} else {
|
|
9262
|
-
singleFetchResult = {
|
|
9263
|
-
data: Object.values(context.actionData || {})[0]
|
|
9264
|
-
};
|
|
9265
|
-
}
|
|
9266
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
9267
|
-
result: singleFetchResult,
|
|
9268
|
-
headers,
|
|
9269
|
-
status: context.statusCode
|
|
9270
|
-
});
|
|
9271
|
-
}
|
|
8975
|
+
dataStrategy: getSingleFetchDataStrategy2({
|
|
8976
|
+
isActionDataRequest: true
|
|
8977
|
+
})
|
|
9272
8978
|
});
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
8979
|
+
if (isResponse(result)) {
|
|
8980
|
+
return {
|
|
9276
8981
|
result: getSingleFetchRedirect(
|
|
9277
8982
|
result.status,
|
|
9278
8983
|
result.headers,
|
|
@@ -9280,16 +8985,47 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
|
|
|
9280
8985
|
),
|
|
9281
8986
|
headers: result.headers,
|
|
9282
8987
|
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
8988
|
+
};
|
|
8989
|
+
}
|
|
8990
|
+
let context = result;
|
|
8991
|
+
let headers = getDocumentHeaders(build, context);
|
|
8992
|
+
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
8993
|
+
return {
|
|
8994
|
+
result: getSingleFetchRedirect(
|
|
8995
|
+
context.statusCode,
|
|
8996
|
+
headers,
|
|
8997
|
+
build.basename
|
|
8998
|
+
),
|
|
8999
|
+
headers,
|
|
9000
|
+
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
9001
|
+
};
|
|
9002
|
+
}
|
|
9003
|
+
if (context.errors) {
|
|
9004
|
+
Object.values(context.errors).forEach((err) => {
|
|
9005
|
+
if (!isRouteErrorResponse(err) || err.error) {
|
|
9006
|
+
handleError(err);
|
|
9007
|
+
}
|
|
9283
9008
|
});
|
|
9009
|
+
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9284
9010
|
}
|
|
9285
|
-
|
|
9011
|
+
let singleFetchResult;
|
|
9012
|
+
if (context.errors) {
|
|
9013
|
+
singleFetchResult = { error: Object.values(context.errors)[0] };
|
|
9014
|
+
} else {
|
|
9015
|
+
singleFetchResult = { data: Object.values(context.actionData || {})[0] };
|
|
9016
|
+
}
|
|
9017
|
+
return {
|
|
9018
|
+
result: singleFetchResult,
|
|
9019
|
+
headers,
|
|
9020
|
+
status: context.statusCode
|
|
9021
|
+
};
|
|
9286
9022
|
} catch (error) {
|
|
9287
9023
|
handleError(error);
|
|
9288
|
-
return
|
|
9024
|
+
return {
|
|
9289
9025
|
result: { error },
|
|
9290
9026
|
headers: new Headers(),
|
|
9291
9027
|
status: 500
|
|
9292
|
-
}
|
|
9028
|
+
};
|
|
9293
9029
|
}
|
|
9294
9030
|
}
|
|
9295
9031
|
async function singleFetchLoaders(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
|
|
@@ -9298,61 +9034,16 @@ async function singleFetchLoaders(build, serverMode, staticHandler, request, han
|
|
|
9298
9034
|
headers: request.headers,
|
|
9299
9035
|
signal: request.signal
|
|
9300
9036
|
});
|
|
9301
|
-
let
|
|
9302
|
-
let loadRouteIds = routesParam ? new Set(routesParam.split(",")) : null;
|
|
9037
|
+
let loadRouteIds = new URL(request.url).searchParams.get("_routes")?.split(",") || void 0;
|
|
9303
9038
|
let result = await staticHandler.query(handlerRequest, {
|
|
9304
9039
|
requestContext: loadContext,
|
|
9305
|
-
filterMatchesToLoad: (m) => !loadRouteIds || loadRouteIds.has(m.route.id),
|
|
9306
9040
|
skipLoaderErrorBubbling: true,
|
|
9307
|
-
|
|
9308
|
-
|
|
9309
|
-
|
|
9310
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
9311
|
-
result: {
|
|
9312
|
-
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
9313
|
-
context.statusCode,
|
|
9314
|
-
headers,
|
|
9315
|
-
build.basename
|
|
9316
|
-
)
|
|
9317
|
-
},
|
|
9318
|
-
headers,
|
|
9319
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
9320
|
-
});
|
|
9321
|
-
}
|
|
9322
|
-
if (context.errors) {
|
|
9323
|
-
Object.values(context.errors).forEach((err) => {
|
|
9324
|
-
if (!isRouteErrorResponse(err) || err.error) {
|
|
9325
|
-
handleError(err);
|
|
9326
|
-
}
|
|
9327
|
-
});
|
|
9328
|
-
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9329
|
-
}
|
|
9330
|
-
let results = {};
|
|
9331
|
-
let loadedMatches = new Set(
|
|
9332
|
-
context.matches.filter(
|
|
9333
|
-
(m) => loadRouteIds ? loadRouteIds.has(m.route.id) : m.route.loader != null
|
|
9334
|
-
).map((m) => m.route.id)
|
|
9335
|
-
);
|
|
9336
|
-
if (context.errors) {
|
|
9337
|
-
for (let [id, error] of Object.entries(context.errors)) {
|
|
9338
|
-
results[id] = { error };
|
|
9339
|
-
}
|
|
9340
|
-
}
|
|
9341
|
-
for (let [id, data2] of Object.entries(context.loaderData)) {
|
|
9342
|
-
if (!(id in results) && loadedMatches.has(id)) {
|
|
9343
|
-
results[id] = { data: data2 };
|
|
9344
|
-
}
|
|
9345
|
-
}
|
|
9346
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
9347
|
-
result: results,
|
|
9348
|
-
headers,
|
|
9349
|
-
status: context.statusCode
|
|
9350
|
-
});
|
|
9351
|
-
}
|
|
9041
|
+
dataStrategy: getSingleFetchDataStrategy2({
|
|
9042
|
+
loadRouteIds
|
|
9043
|
+
})
|
|
9352
9044
|
});
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
return generateSingleFetchResponse(request, build, serverMode, {
|
|
9045
|
+
if (isResponse(result)) {
|
|
9046
|
+
return {
|
|
9356
9047
|
result: {
|
|
9357
9048
|
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
9358
9049
|
result.status,
|
|
@@ -9362,41 +9053,56 @@ async function singleFetchLoaders(build, serverMode, staticHandler, request, han
|
|
|
9362
9053
|
},
|
|
9363
9054
|
headers: result.headers,
|
|
9364
9055
|
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
9056
|
+
};
|
|
9057
|
+
}
|
|
9058
|
+
let context = result;
|
|
9059
|
+
let headers = getDocumentHeaders(build, context);
|
|
9060
|
+
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
9061
|
+
return {
|
|
9062
|
+
result: {
|
|
9063
|
+
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
9064
|
+
context.statusCode,
|
|
9065
|
+
headers,
|
|
9066
|
+
build.basename
|
|
9067
|
+
)
|
|
9068
|
+
},
|
|
9069
|
+
headers,
|
|
9070
|
+
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
9071
|
+
};
|
|
9072
|
+
}
|
|
9073
|
+
if (context.errors) {
|
|
9074
|
+
Object.values(context.errors).forEach((err) => {
|
|
9075
|
+
if (!isRouteErrorResponse(err) || err.error) {
|
|
9076
|
+
handleError(err);
|
|
9077
|
+
}
|
|
9365
9078
|
});
|
|
9079
|
+
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9366
9080
|
}
|
|
9367
|
-
|
|
9081
|
+
let results = {};
|
|
9082
|
+
let loadedMatches = loadRouteIds ? context.matches.filter(
|
|
9083
|
+
(m) => m.route.loader && loadRouteIds.includes(m.route.id)
|
|
9084
|
+
) : context.matches;
|
|
9085
|
+
loadedMatches.forEach((m) => {
|
|
9086
|
+
let { id } = m.route;
|
|
9087
|
+
if (context.errors && context.errors.hasOwnProperty(id)) {
|
|
9088
|
+
results[id] = { error: context.errors[id] };
|
|
9089
|
+
} else if (context.loaderData.hasOwnProperty(id)) {
|
|
9090
|
+
results[id] = { data: context.loaderData[id] };
|
|
9091
|
+
}
|
|
9092
|
+
});
|
|
9093
|
+
return {
|
|
9094
|
+
result: results,
|
|
9095
|
+
headers,
|
|
9096
|
+
status: context.statusCode
|
|
9097
|
+
};
|
|
9368
9098
|
} catch (error) {
|
|
9369
9099
|
handleError(error);
|
|
9370
|
-
return
|
|
9100
|
+
return {
|
|
9371
9101
|
result: { root: { error } },
|
|
9372
9102
|
headers: new Headers(),
|
|
9373
9103
|
status: 500
|
|
9374
|
-
}
|
|
9375
|
-
}
|
|
9376
|
-
}
|
|
9377
|
-
function generateSingleFetchResponse(request, build, serverMode, {
|
|
9378
|
-
result,
|
|
9379
|
-
headers,
|
|
9380
|
-
status
|
|
9381
|
-
}) {
|
|
9382
|
-
let resultHeaders = new Headers(headers);
|
|
9383
|
-
resultHeaders.set("X-Remix-Response", "yes");
|
|
9384
|
-
if (NO_BODY_STATUS_CODES.has(status)) {
|
|
9385
|
-
return new Response(null, { status, headers: resultHeaders });
|
|
9104
|
+
};
|
|
9386
9105
|
}
|
|
9387
|
-
resultHeaders.set("Content-Type", "text/x-script");
|
|
9388
|
-
return new Response(
|
|
9389
|
-
encodeViaTurboStream(
|
|
9390
|
-
result,
|
|
9391
|
-
request.signal,
|
|
9392
|
-
build.entry.module.streamTimeout,
|
|
9393
|
-
serverMode
|
|
9394
|
-
),
|
|
9395
|
-
{
|
|
9396
|
-
status: status || 200,
|
|
9397
|
-
headers: resultHeaders
|
|
9398
|
-
}
|
|
9399
|
-
);
|
|
9400
9106
|
}
|
|
9401
9107
|
function getSingleFetchRedirect(status, headers, basename) {
|
|
9402
9108
|
let redirect2 = headers.get("Location");
|
|
@@ -9459,6 +9165,7 @@ function encodeViaTurboStream(data2, requestSignal, streamTimeout, serverMode) {
|
|
|
9459
9165
|
}
|
|
9460
9166
|
|
|
9461
9167
|
// lib/server-runtime/server.ts
|
|
9168
|
+
var NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([100, 101, 204, 205, 304]);
|
|
9462
9169
|
function derive(build, mode) {
|
|
9463
9170
|
let routes = createRoutes(build.routes);
|
|
9464
9171
|
let dataRoutes = createStaticHandlerDataRoutes(build.routes, build.future);
|
|
@@ -9638,7 +9345,7 @@ async function handleManifestRequest(build, routes, url) {
|
|
|
9638
9345
|
return new Response("Invalid Request", { status: 400 });
|
|
9639
9346
|
}
|
|
9640
9347
|
async function handleSingleFetchRequest(serverMode, build, staticHandler, request, handlerUrl, loadContext, handleError) {
|
|
9641
|
-
let
|
|
9348
|
+
let { result, headers, status } = request.method !== "GET" ? await singleFetchAction(
|
|
9642
9349
|
build,
|
|
9643
9350
|
serverMode,
|
|
9644
9351
|
staticHandler,
|
|
@@ -9655,67 +9362,129 @@ async function handleSingleFetchRequest(serverMode, build, staticHandler, reques
|
|
|
9655
9362
|
loadContext,
|
|
9656
9363
|
handleError
|
|
9657
9364
|
);
|
|
9658
|
-
|
|
9365
|
+
let resultHeaders = new Headers(headers);
|
|
9366
|
+
resultHeaders.set("X-Remix-Response", "yes");
|
|
9367
|
+
if (NO_BODY_STATUS_CODES.has(status)) {
|
|
9368
|
+
return new Response(null, { status, headers: resultHeaders });
|
|
9369
|
+
}
|
|
9370
|
+
resultHeaders.set("Content-Type", "text/x-script");
|
|
9371
|
+
return new Response(
|
|
9372
|
+
encodeViaTurboStream(
|
|
9373
|
+
result,
|
|
9374
|
+
request.signal,
|
|
9375
|
+
build.entry.module.streamTimeout,
|
|
9376
|
+
serverMode
|
|
9377
|
+
),
|
|
9378
|
+
{
|
|
9379
|
+
status: status || 200,
|
|
9380
|
+
headers: resultHeaders
|
|
9381
|
+
}
|
|
9382
|
+
);
|
|
9659
9383
|
}
|
|
9660
9384
|
async function handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, criticalCss) {
|
|
9385
|
+
let context;
|
|
9661
9386
|
try {
|
|
9662
|
-
|
|
9663
|
-
requestContext: loadContext
|
|
9664
|
-
respond: renderHtml
|
|
9387
|
+
context = await staticHandler.query(request, {
|
|
9388
|
+
requestContext: loadContext
|
|
9665
9389
|
});
|
|
9666
|
-
invariant3(
|
|
9667
|
-
isResponse(response),
|
|
9668
|
-
"Expected a Response to be returned from query"
|
|
9669
|
-
);
|
|
9670
|
-
return response;
|
|
9671
9390
|
} catch (error) {
|
|
9672
9391
|
handleError(error);
|
|
9673
9392
|
return new Response(null, { status: 500 });
|
|
9674
9393
|
}
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
|
-
|
|
9679
|
-
|
|
9680
|
-
|
|
9681
|
-
|
|
9394
|
+
if (isResponse(context)) {
|
|
9395
|
+
return context;
|
|
9396
|
+
}
|
|
9397
|
+
let headers = getDocumentHeaders(build, context);
|
|
9398
|
+
if (NO_BODY_STATUS_CODES.has(context.statusCode)) {
|
|
9399
|
+
return new Response(null, { status: context.statusCode, headers });
|
|
9400
|
+
}
|
|
9401
|
+
if (context.errors) {
|
|
9402
|
+
Object.values(context.errors).forEach((err) => {
|
|
9403
|
+
if (!isRouteErrorResponse(err) || err.error) {
|
|
9404
|
+
handleError(err);
|
|
9405
|
+
}
|
|
9406
|
+
});
|
|
9407
|
+
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9408
|
+
}
|
|
9409
|
+
let state = {
|
|
9410
|
+
loaderData: context.loaderData,
|
|
9411
|
+
actionData: context.actionData,
|
|
9412
|
+
errors: serializeErrors2(context.errors, serverMode)
|
|
9413
|
+
};
|
|
9414
|
+
let entryContext = {
|
|
9415
|
+
manifest: build.assets,
|
|
9416
|
+
routeModules: createEntryRouteModules(build.routes),
|
|
9417
|
+
staticHandlerContext: context,
|
|
9418
|
+
criticalCss,
|
|
9419
|
+
serverHandoffString: createServerHandoffString({
|
|
9420
|
+
basename: build.basename,
|
|
9421
|
+
criticalCss,
|
|
9422
|
+
future: build.future,
|
|
9423
|
+
isSpaMode: build.isSpaMode
|
|
9424
|
+
}),
|
|
9425
|
+
serverHandoffStream: encodeViaTurboStream(
|
|
9426
|
+
state,
|
|
9427
|
+
request.signal,
|
|
9428
|
+
build.entry.module.streamTimeout,
|
|
9429
|
+
serverMode
|
|
9430
|
+
),
|
|
9431
|
+
renderMeta: {},
|
|
9432
|
+
future: build.future,
|
|
9433
|
+
isSpaMode: build.isSpaMode,
|
|
9434
|
+
serializeError: (err) => serializeError(err, serverMode)
|
|
9435
|
+
};
|
|
9436
|
+
let handleDocumentRequestFunction = build.entry.module.default;
|
|
9437
|
+
try {
|
|
9438
|
+
return await handleDocumentRequestFunction(
|
|
9439
|
+
request,
|
|
9440
|
+
context.statusCode,
|
|
9441
|
+
headers,
|
|
9442
|
+
entryContext,
|
|
9443
|
+
loadContext
|
|
9444
|
+
);
|
|
9445
|
+
} catch (error) {
|
|
9446
|
+
handleError(error);
|
|
9447
|
+
let errorForSecondRender = error;
|
|
9448
|
+
if (isResponse(error)) {
|
|
9449
|
+
try {
|
|
9450
|
+
let data2 = await unwrapResponse(error);
|
|
9451
|
+
errorForSecondRender = new ErrorResponseImpl(
|
|
9452
|
+
error.status,
|
|
9453
|
+
error.statusText,
|
|
9454
|
+
data2
|
|
9455
|
+
);
|
|
9456
|
+
} catch (e) {
|
|
9457
|
+
}
|
|
9682
9458
|
}
|
|
9459
|
+
context = getStaticContextFromError(
|
|
9460
|
+
staticHandler.dataRoutes,
|
|
9461
|
+
context,
|
|
9462
|
+
errorForSecondRender
|
|
9463
|
+
);
|
|
9683
9464
|
if (context.errors) {
|
|
9684
|
-
Object.values(context.errors).forEach((err) => {
|
|
9685
|
-
if (!isRouteErrorResponse(err) || err.error) {
|
|
9686
|
-
handleError(err);
|
|
9687
|
-
}
|
|
9688
|
-
});
|
|
9689
9465
|
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9690
9466
|
}
|
|
9691
|
-
let
|
|
9467
|
+
let state2 = {
|
|
9692
9468
|
loaderData: context.loaderData,
|
|
9693
9469
|
actionData: context.actionData,
|
|
9694
9470
|
errors: serializeErrors2(context.errors, serverMode)
|
|
9695
9471
|
};
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
routeModules: createEntryRouteModules(build.routes),
|
|
9472
|
+
entryContext = {
|
|
9473
|
+
...entryContext,
|
|
9699
9474
|
staticHandlerContext: context,
|
|
9700
|
-
criticalCss,
|
|
9701
9475
|
serverHandoffString: createServerHandoffString({
|
|
9702
9476
|
basename: build.basename,
|
|
9703
|
-
criticalCss,
|
|
9704
9477
|
future: build.future,
|
|
9705
9478
|
isSpaMode: build.isSpaMode
|
|
9706
9479
|
}),
|
|
9707
9480
|
serverHandoffStream: encodeViaTurboStream(
|
|
9708
|
-
|
|
9481
|
+
state2,
|
|
9709
9482
|
request.signal,
|
|
9710
9483
|
build.entry.module.streamTimeout,
|
|
9711
9484
|
serverMode
|
|
9712
9485
|
),
|
|
9713
|
-
renderMeta: {}
|
|
9714
|
-
future: build.future,
|
|
9715
|
-
isSpaMode: build.isSpaMode,
|
|
9716
|
-
serializeError: (err) => serializeError(err, serverMode)
|
|
9486
|
+
renderMeta: {}
|
|
9717
9487
|
};
|
|
9718
|
-
let handleDocumentRequestFunction = build.entry.module.default;
|
|
9719
9488
|
try {
|
|
9720
9489
|
return await handleDocumentRequestFunction(
|
|
9721
9490
|
request,
|
|
@@ -9724,61 +9493,9 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
|
|
|
9724
9493
|
entryContext,
|
|
9725
9494
|
loadContext
|
|
9726
9495
|
);
|
|
9727
|
-
} catch (
|
|
9728
|
-
handleError(
|
|
9729
|
-
|
|
9730
|
-
if (isResponse(error)) {
|
|
9731
|
-
try {
|
|
9732
|
-
let data2 = await unwrapResponse(error);
|
|
9733
|
-
errorForSecondRender = new ErrorResponseImpl(
|
|
9734
|
-
error.status,
|
|
9735
|
-
error.statusText,
|
|
9736
|
-
data2
|
|
9737
|
-
);
|
|
9738
|
-
} catch (e) {
|
|
9739
|
-
}
|
|
9740
|
-
}
|
|
9741
|
-
context = getStaticContextFromError(
|
|
9742
|
-
staticHandler.dataRoutes,
|
|
9743
|
-
context,
|
|
9744
|
-
errorForSecondRender
|
|
9745
|
-
);
|
|
9746
|
-
if (context.errors) {
|
|
9747
|
-
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9748
|
-
}
|
|
9749
|
-
let state2 = {
|
|
9750
|
-
loaderData: context.loaderData,
|
|
9751
|
-
actionData: context.actionData,
|
|
9752
|
-
errors: serializeErrors2(context.errors, serverMode)
|
|
9753
|
-
};
|
|
9754
|
-
entryContext = {
|
|
9755
|
-
...entryContext,
|
|
9756
|
-
staticHandlerContext: context,
|
|
9757
|
-
serverHandoffString: createServerHandoffString({
|
|
9758
|
-
basename: build.basename,
|
|
9759
|
-
future: build.future,
|
|
9760
|
-
isSpaMode: build.isSpaMode
|
|
9761
|
-
}),
|
|
9762
|
-
serverHandoffStream: encodeViaTurboStream(
|
|
9763
|
-
state2,
|
|
9764
|
-
request.signal,
|
|
9765
|
-
build.entry.module.streamTimeout,
|
|
9766
|
-
serverMode
|
|
9767
|
-
),
|
|
9768
|
-
renderMeta: {}
|
|
9769
|
-
};
|
|
9770
|
-
try {
|
|
9771
|
-
return await handleDocumentRequestFunction(
|
|
9772
|
-
request,
|
|
9773
|
-
context.statusCode,
|
|
9774
|
-
headers,
|
|
9775
|
-
entryContext,
|
|
9776
|
-
loadContext
|
|
9777
|
-
);
|
|
9778
|
-
} catch (error2) {
|
|
9779
|
-
handleError(error2);
|
|
9780
|
-
return returnLastResortErrorResponse(error2, serverMode);
|
|
9781
|
-
}
|
|
9496
|
+
} catch (error2) {
|
|
9497
|
+
handleError(error2);
|
|
9498
|
+
return returnLastResortErrorResponse(error2, serverMode);
|
|
9782
9499
|
}
|
|
9783
9500
|
}
|
|
9784
9501
|
}
|
|
@@ -9786,16 +9503,15 @@ async function handleResourceRequest(serverMode, staticHandler, routeId, request
|
|
|
9786
9503
|
try {
|
|
9787
9504
|
let response = await staticHandler.queryRoute(request, {
|
|
9788
9505
|
routeId,
|
|
9789
|
-
requestContext: loadContext
|
|
9790
|
-
async respond(ctx) {
|
|
9791
|
-
return ctx;
|
|
9792
|
-
}
|
|
9506
|
+
requestContext: loadContext
|
|
9793
9507
|
});
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
|
|
9797
|
-
)
|
|
9798
|
-
|
|
9508
|
+
if (isResponse(response)) {
|
|
9509
|
+
return response;
|
|
9510
|
+
}
|
|
9511
|
+
if (typeof response === "string") {
|
|
9512
|
+
return new Response(response);
|
|
9513
|
+
}
|
|
9514
|
+
return Response.json(response);
|
|
9799
9515
|
} catch (error) {
|
|
9800
9516
|
if (isResponse(error)) {
|
|
9801
9517
|
error.headers.set("X-Remix-Catch", "yes");
|
|
@@ -9807,13 +9523,6 @@ async function handleResourceRequest(serverMode, staticHandler, routeId, request
|
|
|
9807
9523
|
}
|
|
9808
9524
|
return errorResponseToJson(error, serverMode);
|
|
9809
9525
|
}
|
|
9810
|
-
if (error instanceof Error && error.message === "Expected a response from queryRoute") {
|
|
9811
|
-
let newError = new Error(
|
|
9812
|
-
"Expected a Response to be returned from resource route handler"
|
|
9813
|
-
);
|
|
9814
|
-
handleError(newError);
|
|
9815
|
-
return returnLastResortErrorResponse(newError, serverMode);
|
|
9816
|
-
}
|
|
9817
9526
|
handleError(error);
|
|
9818
9527
|
return returnLastResortErrorResponse(error, serverMode);
|
|
9819
9528
|
}
|