react-router 0.0.0-experimental-9ea41ead4 → 0.0.0-experimental-beaa4f52a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/development/{chunk-RSP5WONC.mjs → chunk-3SBCR7VW.mjs} +759 -463
- package/dist/development/dom-export.d.mts +14 -4
- package/dist/development/dom-export.d.ts +14 -4
- package/dist/development/dom-export.js +269 -201
- package/dist/development/dom-export.mjs +9 -6
- package/dist/{production/fog-of-war-CTZ6x_bd.d.mts → development/fog-of-war-CYAe8qUt.d.mts} +93 -17
- package/dist/development/{fog-of-war-CTZ6x_bd.d.mts → fog-of-war-CrM4EOZM.d.ts} +93 -17
- package/dist/development/index.d.mts +10 -50
- package/dist/development/index.d.ts +10 -50
- package/dist/development/index.js +759 -463
- package/dist/development/index.mjs +2 -2
- package/dist/development/lib/types/route-module.d.mts +13 -5
- package/dist/development/lib/types/route-module.d.ts +13 -5
- package/dist/development/lib/types/route-module.js +1 -1
- package/dist/development/lib/types/route-module.mjs +1 -1
- package/dist/{production/route-data-JFOfNyPS.d.mts → development/route-data-C9zMg-qq.d.mts} +87 -18
- package/dist/development/{route-data-JFOfNyPS.d.mts → route-data-C9zMg-qq.d.ts} +87 -18
- package/dist/production/{chunk-3VYQCA5J.mjs → chunk-DRRQRV77.mjs} +759 -463
- package/dist/production/dom-export.d.mts +14 -4
- package/dist/production/dom-export.d.ts +14 -4
- package/dist/production/dom-export.js +269 -201
- package/dist/production/dom-export.mjs +9 -6
- package/dist/{development/fog-of-war-B3edLoNW.d.ts → production/fog-of-war-CYAe8qUt.d.mts} +93 -17
- package/dist/production/{fog-of-war-B3edLoNW.d.ts → fog-of-war-CrM4EOZM.d.ts} +93 -17
- package/dist/production/index.d.mts +10 -50
- package/dist/production/index.d.ts +10 -50
- package/dist/production/index.js +759 -463
- package/dist/production/index.mjs +2 -2
- package/dist/production/lib/types/route-module.d.mts +13 -5
- package/dist/production/lib/types/route-module.d.ts +13 -5
- package/dist/production/lib/types/route-module.js +1 -1
- package/dist/production/lib/types/route-module.mjs +1 -1
- package/dist/{development/route-data-JFOfNyPS.d.ts → production/route-data-C9zMg-qq.d.mts} +87 -18
- package/dist/production/{route-data-JFOfNyPS.d.ts → route-data-C9zMg-qq.d.ts} +87 -18
- package/package.json +1 -1
- package/dist/development/data-CQbyyGzl.d.mts +0 -11
- package/dist/development/data-CQbyyGzl.d.ts +0 -11
- package/dist/production/data-CQbyyGzl.d.mts +0 -11
- package/dist/production/data-CQbyyGzl.d.ts +0 -11
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v0.0.0-experimental-
|
|
2
|
+
* react-router v0.0.0-experimental-beaa4f52a
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -684,7 +684,7 @@ function decodePath(value) {
|
|
|
684
684
|
} catch (error) {
|
|
685
685
|
warning(
|
|
686
686
|
false,
|
|
687
|
-
`The URL path "${value}" could not be decoded because it is
|
|
687
|
+
`The URL path "${value}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${error}).`
|
|
688
688
|
);
|
|
689
689
|
return value;
|
|
690
690
|
}
|
|
@@ -907,6 +907,7 @@ function createRouter(init) {
|
|
|
907
907
|
);
|
|
908
908
|
let inFlightDataRoutes;
|
|
909
909
|
let basename = init.basename || "/";
|
|
910
|
+
let routerContext = typeof init.context !== "undefined" ? init.context : {};
|
|
910
911
|
let dataStrategyImpl = init.dataStrategy || defaultDataStrategy;
|
|
911
912
|
let patchRoutesOnNavigationImpl = init.patchRoutesOnNavigation;
|
|
912
913
|
let future = {
|
|
@@ -1347,6 +1348,7 @@ function createRouter(init) {
|
|
|
1347
1348
|
pendingNavigationController.signal,
|
|
1348
1349
|
opts && opts.submission
|
|
1349
1350
|
);
|
|
1351
|
+
let scopedContext = { ...routerContext };
|
|
1350
1352
|
let pendingActionResult;
|
|
1351
1353
|
if (opts && opts.pendingError) {
|
|
1352
1354
|
pendingActionResult = [
|
|
@@ -1359,6 +1361,7 @@ function createRouter(init) {
|
|
|
1359
1361
|
location,
|
|
1360
1362
|
opts.submission,
|
|
1361
1363
|
matches,
|
|
1364
|
+
scopedContext,
|
|
1362
1365
|
fogOfWar.active,
|
|
1363
1366
|
{ replace: opts.replace, flushSync }
|
|
1364
1367
|
);
|
|
@@ -1399,6 +1402,7 @@ function createRouter(init) {
|
|
|
1399
1402
|
request,
|
|
1400
1403
|
location,
|
|
1401
1404
|
matches,
|
|
1405
|
+
scopedContext,
|
|
1402
1406
|
fogOfWar.active,
|
|
1403
1407
|
loadingNavigation,
|
|
1404
1408
|
opts && opts.submission,
|
|
@@ -1419,7 +1423,7 @@ function createRouter(init) {
|
|
|
1419
1423
|
errors
|
|
1420
1424
|
});
|
|
1421
1425
|
}
|
|
1422
|
-
async function handleAction(request, location, submission, matches, isFogOfWar, opts = {}) {
|
|
1426
|
+
async function handleAction(request, location, submission, matches, scopedContext, isFogOfWar, opts = {}) {
|
|
1423
1427
|
interruptActiveLoads();
|
|
1424
1428
|
let navigation = getSubmittingNavigation(location, submission);
|
|
1425
1429
|
updateState({ navigation }, { flushSync: opts.flushSync === true });
|
|
@@ -1473,15 +1477,23 @@ function createRouter(init) {
|
|
|
1473
1477
|
})
|
|
1474
1478
|
};
|
|
1475
1479
|
} else {
|
|
1476
|
-
let results = await
|
|
1480
|
+
let results = await callRouterDataStrategy(
|
|
1477
1481
|
"action",
|
|
1478
|
-
state,
|
|
1479
1482
|
request,
|
|
1480
1483
|
[actionMatch],
|
|
1481
1484
|
matches,
|
|
1485
|
+
scopedContext,
|
|
1482
1486
|
null
|
|
1483
1487
|
);
|
|
1484
1488
|
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
|
+
}
|
|
1485
1497
|
if (request.signal.aborted) {
|
|
1486
1498
|
return { shortCircuited: true };
|
|
1487
1499
|
}
|
|
@@ -1519,7 +1531,7 @@ function createRouter(init) {
|
|
|
1519
1531
|
pendingActionResult: [actionMatch.route.id, result]
|
|
1520
1532
|
};
|
|
1521
1533
|
}
|
|
1522
|
-
async function handleLoaders(request, location, matches, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync, pendingActionResult) {
|
|
1534
|
+
async function handleLoaders(request, location, matches, scopedContext, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync, pendingActionResult) {
|
|
1523
1535
|
let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
|
|
1524
1536
|
let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
|
|
1525
1537
|
let shouldUpdateNavigationState = !isUninterruptedRevalidation && !initialHydration;
|
|
@@ -1629,11 +1641,11 @@ function createRouter(init) {
|
|
|
1629
1641
|
);
|
|
1630
1642
|
}
|
|
1631
1643
|
let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
|
1632
|
-
state,
|
|
1633
1644
|
matches,
|
|
1634
1645
|
matchesToLoad,
|
|
1635
1646
|
revalidatingFetchers,
|
|
1636
|
-
request
|
|
1647
|
+
request,
|
|
1648
|
+
scopedContext
|
|
1637
1649
|
);
|
|
1638
1650
|
if (request.signal.aborted) {
|
|
1639
1651
|
return { shortCircuited: true };
|
|
@@ -1741,6 +1753,7 @@ function createRouter(init) {
|
|
|
1741
1753
|
return;
|
|
1742
1754
|
}
|
|
1743
1755
|
let match = getTargetMatch(matches, path);
|
|
1756
|
+
let scopedContext = { ...routerContext };
|
|
1744
1757
|
let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1745
1758
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
1746
1759
|
await handleFetcherAction(
|
|
@@ -1749,6 +1762,7 @@ function createRouter(init) {
|
|
|
1749
1762
|
path,
|
|
1750
1763
|
match,
|
|
1751
1764
|
matches,
|
|
1765
|
+
scopedContext,
|
|
1752
1766
|
fogOfWar.active,
|
|
1753
1767
|
flushSync,
|
|
1754
1768
|
preventScrollReset,
|
|
@@ -1763,13 +1777,14 @@ function createRouter(init) {
|
|
|
1763
1777
|
path,
|
|
1764
1778
|
match,
|
|
1765
1779
|
matches,
|
|
1780
|
+
scopedContext,
|
|
1766
1781
|
fogOfWar.active,
|
|
1767
1782
|
flushSync,
|
|
1768
1783
|
preventScrollReset,
|
|
1769
1784
|
submission
|
|
1770
1785
|
);
|
|
1771
1786
|
}
|
|
1772
|
-
async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
1787
|
+
async function handleFetcherAction(key, routeId, path, match, requestMatches, scopedContext, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
1773
1788
|
interruptActiveLoads();
|
|
1774
1789
|
fetchLoadMatches.delete(key);
|
|
1775
1790
|
function detectAndHandle405Error(m) {
|
|
@@ -1827,12 +1842,12 @@ function createRouter(init) {
|
|
|
1827
1842
|
}
|
|
1828
1843
|
fetchControllers.set(key, abortController);
|
|
1829
1844
|
let originatingLoadId = incrementingLoadId;
|
|
1830
|
-
let actionResults = await
|
|
1845
|
+
let actionResults = await callRouterDataStrategy(
|
|
1831
1846
|
"action",
|
|
1832
|
-
state,
|
|
1833
1847
|
fetchRequest,
|
|
1834
1848
|
[match],
|
|
1835
1849
|
requestMatches,
|
|
1850
|
+
scopedContext,
|
|
1836
1851
|
key
|
|
1837
1852
|
);
|
|
1838
1853
|
let actionResult = actionResults[match.route.id];
|
|
@@ -1916,11 +1931,11 @@ function createRouter(init) {
|
|
|
1916
1931
|
abortPendingFetchRevalidations
|
|
1917
1932
|
);
|
|
1918
1933
|
let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
|
1919
|
-
state,
|
|
1920
1934
|
matches,
|
|
1921
1935
|
matchesToLoad,
|
|
1922
1936
|
revalidatingFetchers,
|
|
1923
|
-
revalidationRequest
|
|
1937
|
+
revalidationRequest,
|
|
1938
|
+
scopedContext
|
|
1924
1939
|
);
|
|
1925
1940
|
if (abortController.signal.aborted) {
|
|
1926
1941
|
return;
|
|
@@ -1987,7 +2002,7 @@ function createRouter(init) {
|
|
|
1987
2002
|
isRevalidationRequired = false;
|
|
1988
2003
|
}
|
|
1989
2004
|
}
|
|
1990
|
-
async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
2005
|
+
async function handleFetcherLoader(key, routeId, path, match, matches, scopedContext, isFogOfWar, flushSync, preventScrollReset, submission) {
|
|
1991
2006
|
let existingFetcher = state.fetchers.get(key);
|
|
1992
2007
|
updateFetcherState(
|
|
1993
2008
|
key,
|
|
@@ -2029,12 +2044,12 @@ function createRouter(init) {
|
|
|
2029
2044
|
}
|
|
2030
2045
|
fetchControllers.set(key, abortController);
|
|
2031
2046
|
let originatingLoadId = incrementingLoadId;
|
|
2032
|
-
let results = await
|
|
2047
|
+
let results = await callRouterDataStrategy(
|
|
2033
2048
|
"loader",
|
|
2034
|
-
state,
|
|
2035
2049
|
fetchRequest,
|
|
2036
2050
|
[match],
|
|
2037
2051
|
matches,
|
|
2052
|
+
scopedContext,
|
|
2038
2053
|
key
|
|
2039
2054
|
);
|
|
2040
2055
|
let result = results[match.route.id];
|
|
@@ -2136,20 +2151,20 @@ function createRouter(init) {
|
|
|
2136
2151
|
});
|
|
2137
2152
|
}
|
|
2138
2153
|
}
|
|
2139
|
-
async function
|
|
2154
|
+
async function callRouterDataStrategy(type, request, matchesToLoad, matches, scopedContext, fetcherKey) {
|
|
2140
2155
|
let results;
|
|
2141
2156
|
let dataResults = {};
|
|
2142
2157
|
try {
|
|
2143
2158
|
results = await callDataStrategyImpl(
|
|
2144
2159
|
dataStrategyImpl,
|
|
2145
2160
|
type,
|
|
2146
|
-
state2,
|
|
2147
2161
|
request,
|
|
2148
2162
|
matchesToLoad,
|
|
2149
2163
|
matches,
|
|
2150
2164
|
fetcherKey,
|
|
2151
2165
|
manifest,
|
|
2152
|
-
mapRouteProperties2
|
|
2166
|
+
mapRouteProperties2,
|
|
2167
|
+
scopedContext
|
|
2153
2168
|
);
|
|
2154
2169
|
} catch (e) {
|
|
2155
2170
|
matchesToLoad.forEach((m) => {
|
|
@@ -2181,24 +2196,24 @@ function createRouter(init) {
|
|
|
2181
2196
|
}
|
|
2182
2197
|
return dataResults;
|
|
2183
2198
|
}
|
|
2184
|
-
async function callLoadersAndMaybeResolveData(
|
|
2185
|
-
let loaderResultsPromise =
|
|
2199
|
+
async function callLoadersAndMaybeResolveData(matches, matchesToLoad, fetchersToLoad, request, scopedContext) {
|
|
2200
|
+
let loaderResultsPromise = callRouterDataStrategy(
|
|
2186
2201
|
"loader",
|
|
2187
|
-
state2,
|
|
2188
2202
|
request,
|
|
2189
2203
|
matchesToLoad,
|
|
2190
2204
|
matches,
|
|
2205
|
+
scopedContext,
|
|
2191
2206
|
null
|
|
2192
2207
|
);
|
|
2193
2208
|
let fetcherResultsPromise = Promise.all(
|
|
2194
2209
|
fetchersToLoad.map(async (f) => {
|
|
2195
2210
|
if (f.matches && f.match && f.controller) {
|
|
2196
|
-
let results = await
|
|
2211
|
+
let results = await callRouterDataStrategy(
|
|
2197
2212
|
"loader",
|
|
2198
|
-
state2,
|
|
2199
2213
|
createClientSideRequest(init.history, f.path, f.controller.signal),
|
|
2200
2214
|
[f.match],
|
|
2201
2215
|
f.matches,
|
|
2216
|
+
scopedContext,
|
|
2202
2217
|
f.key
|
|
2203
2218
|
);
|
|
2204
2219
|
let result = results[f.match.route.id];
|
|
@@ -2574,17 +2589,21 @@ function createStaticHandler(routes, opts) {
|
|
|
2574
2589
|
);
|
|
2575
2590
|
async function query(request, {
|
|
2576
2591
|
requestContext,
|
|
2592
|
+
filterMatchesToLoad,
|
|
2577
2593
|
skipLoaderErrorBubbling,
|
|
2578
|
-
|
|
2594
|
+
skipRevalidation,
|
|
2595
|
+
dataStrategy,
|
|
2596
|
+
respond
|
|
2579
2597
|
} = {}) {
|
|
2580
2598
|
let url = new URL(request.url);
|
|
2581
2599
|
let method = request.method;
|
|
2582
2600
|
let location = createLocation("", createPath(url), null, "default");
|
|
2583
2601
|
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2602
|
+
let staticContext;
|
|
2584
2603
|
if (!isValidMethod(method) && method !== "HEAD") {
|
|
2585
2604
|
let error = getInternalRouterError(405, { method });
|
|
2586
2605
|
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
2587
|
-
|
|
2606
|
+
staticContext = {
|
|
2588
2607
|
basename,
|
|
2589
2608
|
location,
|
|
2590
2609
|
matches: methodNotAllowedMatches,
|
|
@@ -2600,7 +2619,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2600
2619
|
} else if (!matches) {
|
|
2601
2620
|
let error = getInternalRouterError(404, { pathname: location.pathname });
|
|
2602
2621
|
let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
2603
|
-
|
|
2622
|
+
staticContext = {
|
|
2604
2623
|
basename,
|
|
2605
2624
|
location,
|
|
2606
2625
|
matches: notFoundMatches,
|
|
@@ -2613,25 +2632,118 @@ function createStaticHandler(routes, opts) {
|
|
|
2613
2632
|
loaderHeaders: {},
|
|
2614
2633
|
actionHeaders: {}
|
|
2615
2634
|
};
|
|
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
|
+
};
|
|
2616
2735
|
}
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
matches,
|
|
2621
|
-
requestContext,
|
|
2622
|
-
dataStrategy || null,
|
|
2623
|
-
skipLoaderErrorBubbling === true,
|
|
2624
|
-
null
|
|
2625
|
-
);
|
|
2626
|
-
if (isResponse(result)) {
|
|
2627
|
-
return result;
|
|
2736
|
+
if (respond) {
|
|
2737
|
+
let res = await respond(staticContext);
|
|
2738
|
+
return res;
|
|
2628
2739
|
}
|
|
2629
|
-
return
|
|
2740
|
+
return staticContext;
|
|
2630
2741
|
}
|
|
2631
2742
|
async function queryRoute(request, {
|
|
2632
2743
|
routeId,
|
|
2633
2744
|
requestContext,
|
|
2634
|
-
dataStrategy
|
|
2745
|
+
dataStrategy,
|
|
2746
|
+
respond
|
|
2635
2747
|
} = {}) {
|
|
2636
2748
|
let url = new URL(request.url);
|
|
2637
2749
|
let method = request.method;
|
|
@@ -2651,31 +2763,77 @@ function createStaticHandler(routes, opts) {
|
|
|
2651
2763
|
} else if (!match) {
|
|
2652
2764
|
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
2653
2765
|
}
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2766
|
+
if (respond) {
|
|
2767
|
+
let response = await runMiddlewarePipeline(
|
|
2768
|
+
{
|
|
2769
|
+
request,
|
|
2770
|
+
matches,
|
|
2771
|
+
params: matches[0].params,
|
|
2772
|
+
context: requestContext
|
|
2773
|
+
},
|
|
2774
|
+
matches.length - 1,
|
|
2775
|
+
true,
|
|
2776
|
+
async () => {
|
|
2777
|
+
let result = await callQueryHandlers(
|
|
2778
|
+
request,
|
|
2779
|
+
location,
|
|
2780
|
+
matches,
|
|
2781
|
+
requestContext,
|
|
2782
|
+
dataStrategy || defaultDataStrategyWithoutMiddleware,
|
|
2783
|
+
false,
|
|
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;
|
|
2675
2834
|
}
|
|
2676
|
-
return void 0;
|
|
2677
2835
|
}
|
|
2678
|
-
async function
|
|
2836
|
+
async function callQueryHandlers(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
|
|
2679
2837
|
invariant(
|
|
2680
2838
|
request.signal,
|
|
2681
2839
|
"query()/queryRoute() requests must contain an AbortController signal"
|
|
@@ -2689,7 +2847,9 @@ function createStaticHandler(routes, opts) {
|
|
|
2689
2847
|
requestContext,
|
|
2690
2848
|
dataStrategy,
|
|
2691
2849
|
skipLoaderErrorBubbling,
|
|
2692
|
-
routeMatch != null
|
|
2850
|
+
routeMatch != null,
|
|
2851
|
+
filterMatchesToLoad,
|
|
2852
|
+
skipRevalidation
|
|
2693
2853
|
);
|
|
2694
2854
|
return result2;
|
|
2695
2855
|
}
|
|
@@ -2699,7 +2859,8 @@ function createStaticHandler(routes, opts) {
|
|
|
2699
2859
|
requestContext,
|
|
2700
2860
|
dataStrategy,
|
|
2701
2861
|
skipLoaderErrorBubbling,
|
|
2702
|
-
routeMatch
|
|
2862
|
+
routeMatch,
|
|
2863
|
+
filterMatchesToLoad
|
|
2703
2864
|
);
|
|
2704
2865
|
return isResponse(result) ? result : {
|
|
2705
2866
|
...result,
|
|
@@ -2719,7 +2880,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2719
2880
|
throw e;
|
|
2720
2881
|
}
|
|
2721
2882
|
}
|
|
2722
|
-
async function submit(request, matches, actionMatch, requestContext, dataStrategy, skipLoaderErrorBubbling, isRouteRequest) {
|
|
2883
|
+
async function submit(request, matches, actionMatch, requestContext, dataStrategy, skipLoaderErrorBubbling, isRouteRequest, filterMatchesToLoad, skipRevalidation) {
|
|
2723
2884
|
let result;
|
|
2724
2885
|
if (!actionMatch.route.action && !actionMatch.route.lazy) {
|
|
2725
2886
|
let error = getInternalRouterError(405, {
|
|
@@ -2735,7 +2896,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2735
2896
|
error
|
|
2736
2897
|
};
|
|
2737
2898
|
} else {
|
|
2738
|
-
let results = await
|
|
2899
|
+
let results = await callStaticHandlerDataStrategy(
|
|
2739
2900
|
"action",
|
|
2740
2901
|
request,
|
|
2741
2902
|
[actionMatch],
|
|
@@ -2773,6 +2934,36 @@ function createStaticHandler(routes, opts) {
|
|
|
2773
2934
|
actionHeaders: {}
|
|
2774
2935
|
};
|
|
2775
2936
|
}
|
|
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
|
+
}
|
|
2776
2967
|
let loaderRequest = new Request(request.url, {
|
|
2777
2968
|
headers: request.headers,
|
|
2778
2969
|
redirect: request.redirect,
|
|
@@ -2780,17 +2971,18 @@ function createStaticHandler(routes, opts) {
|
|
|
2780
2971
|
});
|
|
2781
2972
|
if (isErrorResult(result)) {
|
|
2782
2973
|
let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
|
|
2783
|
-
let
|
|
2974
|
+
let handlerContext2 = await loadRouteData(
|
|
2784
2975
|
loaderRequest,
|
|
2785
2976
|
matches,
|
|
2786
2977
|
requestContext,
|
|
2787
2978
|
dataStrategy,
|
|
2788
2979
|
skipLoaderErrorBubbling,
|
|
2789
2980
|
null,
|
|
2981
|
+
filterMatchesToLoad,
|
|
2790
2982
|
[boundaryMatch.route.id, result]
|
|
2791
2983
|
);
|
|
2792
2984
|
return {
|
|
2793
|
-
...
|
|
2985
|
+
...handlerContext2,
|
|
2794
2986
|
statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500,
|
|
2795
2987
|
actionData: null,
|
|
2796
2988
|
actionHeaders: {
|
|
@@ -2798,16 +2990,17 @@ function createStaticHandler(routes, opts) {
|
|
|
2798
2990
|
}
|
|
2799
2991
|
};
|
|
2800
2992
|
}
|
|
2801
|
-
let
|
|
2993
|
+
let handlerContext = await loadRouteData(
|
|
2802
2994
|
loaderRequest,
|
|
2803
2995
|
matches,
|
|
2804
2996
|
requestContext,
|
|
2805
2997
|
dataStrategy,
|
|
2806
2998
|
skipLoaderErrorBubbling,
|
|
2807
|
-
null
|
|
2999
|
+
null,
|
|
3000
|
+
filterMatchesToLoad
|
|
2808
3001
|
);
|
|
2809
3002
|
return {
|
|
2810
|
-
...
|
|
3003
|
+
...handlerContext,
|
|
2811
3004
|
actionData: {
|
|
2812
3005
|
[actionMatch.route.id]: result.data
|
|
2813
3006
|
},
|
|
@@ -2816,7 +3009,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2816
3009
|
actionHeaders: result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
|
2817
3010
|
};
|
|
2818
3011
|
}
|
|
2819
|
-
async function loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, pendingActionResult) {
|
|
3012
|
+
async function loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, pendingActionResult) {
|
|
2820
3013
|
let isRouteRequest = routeMatch != null;
|
|
2821
3014
|
if (isRouteRequest && !routeMatch?.route.loader && !routeMatch?.route.lazy) {
|
|
2822
3015
|
throw getInternalRouterError(400, {
|
|
@@ -2827,7 +3020,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2827
3020
|
}
|
|
2828
3021
|
let requestMatches = routeMatch ? [routeMatch] : pendingActionResult && isErrorResult(pendingActionResult[1]) ? getLoaderMatchesUntilBoundary(matches, pendingActionResult[0]) : matches;
|
|
2829
3022
|
let matchesToLoad = requestMatches.filter(
|
|
2830
|
-
(m) => m.route.loader || m.route.lazy
|
|
3023
|
+
(m) => (m.route.loader || m.route.lazy) && (!filterMatchesToLoad || filterMatchesToLoad(m))
|
|
2831
3024
|
);
|
|
2832
3025
|
if (matchesToLoad.length === 0) {
|
|
2833
3026
|
return {
|
|
@@ -2844,7 +3037,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2844
3037
|
loaderHeaders: {}
|
|
2845
3038
|
};
|
|
2846
3039
|
}
|
|
2847
|
-
let results = await
|
|
3040
|
+
let results = await callStaticHandlerDataStrategy(
|
|
2848
3041
|
"loader",
|
|
2849
3042
|
request,
|
|
2850
3043
|
matchesToLoad,
|
|
@@ -2856,7 +3049,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2856
3049
|
if (request.signal.aborted) {
|
|
2857
3050
|
throwStaticHandlerAbortedError(request, isRouteRequest);
|
|
2858
3051
|
}
|
|
2859
|
-
let
|
|
3052
|
+
let handlerContext = processRouteLoaderData(
|
|
2860
3053
|
matches,
|
|
2861
3054
|
results,
|
|
2862
3055
|
pendingActionResult,
|
|
@@ -2868,19 +3061,18 @@ function createStaticHandler(routes, opts) {
|
|
|
2868
3061
|
);
|
|
2869
3062
|
matches.forEach((match) => {
|
|
2870
3063
|
if (!executedLoaders.has(match.route.id)) {
|
|
2871
|
-
|
|
3064
|
+
handlerContext.loaderData[match.route.id] = null;
|
|
2872
3065
|
}
|
|
2873
3066
|
});
|
|
2874
3067
|
return {
|
|
2875
|
-
...
|
|
3068
|
+
...handlerContext,
|
|
2876
3069
|
matches
|
|
2877
3070
|
};
|
|
2878
3071
|
}
|
|
2879
|
-
async function
|
|
3072
|
+
async function callStaticHandlerDataStrategy(type, request, matchesToLoad, matches, isRouteRequest, requestContext, dataStrategy) {
|
|
2880
3073
|
let results = await callDataStrategyImpl(
|
|
2881
3074
|
dataStrategy || defaultDataStrategy,
|
|
2882
3075
|
type,
|
|
2883
|
-
null,
|
|
2884
3076
|
request,
|
|
2885
3077
|
matchesToLoad,
|
|
2886
3078
|
matches,
|
|
@@ -2920,15 +3112,15 @@ function createStaticHandler(routes, opts) {
|
|
|
2920
3112
|
queryRoute
|
|
2921
3113
|
};
|
|
2922
3114
|
}
|
|
2923
|
-
function getStaticContextFromError(routes,
|
|
2924
|
-
let
|
|
2925
|
-
|
|
3115
|
+
function getStaticContextFromError(routes, handlerContext, error, boundaryId) {
|
|
3116
|
+
let errorBoundaryId = boundaryId || handlerContext._deepestRenderedBoundaryId || routes[0].id;
|
|
3117
|
+
return {
|
|
3118
|
+
...handlerContext,
|
|
2926
3119
|
statusCode: isRouteErrorResponse(error) ? error.status : 500,
|
|
2927
3120
|
errors: {
|
|
2928
|
-
[
|
|
3121
|
+
[errorBoundaryId]: error
|
|
2929
3122
|
}
|
|
2930
3123
|
};
|
|
2931
|
-
return newContext;
|
|
2932
3124
|
}
|
|
2933
3125
|
function throwStaticHandlerAbortedError(request, isRouteRequest) {
|
|
2934
3126
|
if (request.signal.reason !== void 0) {
|
|
@@ -3321,20 +3513,141 @@ async function loadLazyRouteModule(route, mapRouteProperties2, manifest) {
|
|
|
3321
3513
|
lazy: void 0
|
|
3322
3514
|
});
|
|
3323
3515
|
}
|
|
3324
|
-
async function
|
|
3325
|
-
matches
|
|
3326
|
-
|
|
3327
|
-
let matchesToLoad = matches.filter((m) => m.shouldLoad);
|
|
3516
|
+
async function defaultDataStrategyWithoutMiddleware(args) {
|
|
3517
|
+
let matchesToLoad = args.matches.filter((m) => m.shouldLoad);
|
|
3518
|
+
let keyedResults = {};
|
|
3328
3519
|
let results = await Promise.all(matchesToLoad.map((m) => m.resolve()));
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3520
|
+
results.forEach((result, i) => {
|
|
3521
|
+
keyedResults[matchesToLoad[i].route.id] = result;
|
|
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
|
+
}
|
|
3332
3549
|
);
|
|
3550
|
+
return results;
|
|
3333
3551
|
}
|
|
3334
|
-
async function
|
|
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
|
+
}
|
|
3584
|
+
var MiddlewareError = class {
|
|
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) {
|
|
3335
3639
|
let loadRouteDefinitionsPromises = matches.map(
|
|
3336
3640
|
(m) => m.route.lazy ? loadLazyRouteModule(m.route, mapRouteProperties2, manifest) : void 0
|
|
3337
3641
|
);
|
|
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
|
+
}
|
|
3338
3651
|
let dsMatches = matches.map((match, i) => {
|
|
3339
3652
|
let loadRoutePromise = loadRouteDefinitionsPromises[i];
|
|
3340
3653
|
let shouldLoad = matchesToLoad.some((m) => m.route.id === match.route.id);
|
|
@@ -3348,7 +3661,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matc
|
|
|
3348
3661
|
match,
|
|
3349
3662
|
loadRoutePromise,
|
|
3350
3663
|
handlerOverride,
|
|
3351
|
-
|
|
3664
|
+
scopedContext
|
|
3352
3665
|
) : Promise.resolve({ type: "data" /* data */, result: void 0 });
|
|
3353
3666
|
};
|
|
3354
3667
|
return {
|
|
@@ -3362,7 +3675,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matc
|
|
|
3362
3675
|
request,
|
|
3363
3676
|
params: matches[0].params,
|
|
3364
3677
|
fetcherKey,
|
|
3365
|
-
context:
|
|
3678
|
+
context: scopedContext
|
|
3366
3679
|
});
|
|
3367
3680
|
try {
|
|
3368
3681
|
await Promise.all(loadRouteDefinitionsPromises);
|
|
@@ -3370,7 +3683,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matc
|
|
|
3370
3683
|
}
|
|
3371
3684
|
return results;
|
|
3372
3685
|
}
|
|
3373
|
-
async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride,
|
|
3686
|
+
async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride, scopedContext) {
|
|
3374
3687
|
let result;
|
|
3375
3688
|
let onReject;
|
|
3376
3689
|
let runHandler = (handler) => {
|
|
@@ -3390,7 +3703,7 @@ async function callLoaderOrAction(type, request, match, loadRoutePromise, handle
|
|
|
3390
3703
|
{
|
|
3391
3704
|
request,
|
|
3392
3705
|
params: match.params,
|
|
3393
|
-
context:
|
|
3706
|
+
context: scopedContext
|
|
3394
3707
|
},
|
|
3395
3708
|
...ctx !== void 0 ? [ctx] : []
|
|
3396
3709
|
);
|
|
@@ -4697,6 +5010,7 @@ function mapRouteProperties(route) {
|
|
|
4697
5010
|
function createMemoryRouter(routes, opts) {
|
|
4698
5011
|
return createRouter({
|
|
4699
5012
|
basename: opts?.basename,
|
|
5013
|
+
context: opts?.context,
|
|
4700
5014
|
future: opts?.future,
|
|
4701
5015
|
history: createMemoryHistory({
|
|
4702
5016
|
initialEntries: opts?.initialEntries,
|
|
@@ -5348,7 +5662,7 @@ function getKeyedLinksForMatches(matches, routeModules, manifest) {
|
|
|
5348
5662
|
module?.links?.() || []
|
|
5349
5663
|
];
|
|
5350
5664
|
}).flat(2);
|
|
5351
|
-
let preloads =
|
|
5665
|
+
let preloads = getCurrentPageModulePreloadHrefs(matches, manifest);
|
|
5352
5666
|
return dedupeLinkDescriptors(descriptors, preloads);
|
|
5353
5667
|
}
|
|
5354
5668
|
async function prefetchStyleLinks(route, routeModule) {
|
|
@@ -5472,21 +5786,25 @@ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, loca
|
|
|
5472
5786
|
}
|
|
5473
5787
|
return [];
|
|
5474
5788
|
}
|
|
5475
|
-
function getModuleLinkHrefs(matches,
|
|
5789
|
+
function getModuleLinkHrefs(matches, manifestPatch) {
|
|
5476
5790
|
return dedupeHrefs(
|
|
5477
5791
|
matches.map((match) => {
|
|
5478
|
-
let route =
|
|
5792
|
+
let route = manifestPatch.routes[match.route.id];
|
|
5479
5793
|
if (!route) return [];
|
|
5480
5794
|
let hrefs = [route.module];
|
|
5481
|
-
if (route.
|
|
5482
|
-
hrefs = hrefs.concat(route.
|
|
5483
|
-
}
|
|
5484
|
-
if (route.clientLoaderModule) {
|
|
5485
|
-
hrefs = hrefs.concat(route.clientLoaderModule);
|
|
5486
|
-
}
|
|
5487
|
-
if (includeHydrateFallback && route.hydrateFallbackModule) {
|
|
5488
|
-
hrefs = hrefs.concat(route.hydrateFallbackModule);
|
|
5795
|
+
if (route.imports) {
|
|
5796
|
+
hrefs = hrefs.concat(route.imports);
|
|
5489
5797
|
}
|
|
5798
|
+
return hrefs;
|
|
5799
|
+
}).flat(1)
|
|
5800
|
+
);
|
|
5801
|
+
}
|
|
5802
|
+
function getCurrentPageModulePreloadHrefs(matches, manifest) {
|
|
5803
|
+
return dedupeHrefs(
|
|
5804
|
+
matches.map((match) => {
|
|
5805
|
+
let route = manifest.routes[match.route.id];
|
|
5806
|
+
if (!route) return [];
|
|
5807
|
+
let hrefs = [route.module];
|
|
5490
5808
|
if (route.imports) {
|
|
5491
5809
|
hrefs = hrefs.concat(route.imports);
|
|
5492
5810
|
}
|
|
@@ -5641,21 +5959,63 @@ function StreamTransfer({
|
|
|
5641
5959
|
)));
|
|
5642
5960
|
}
|
|
5643
5961
|
}
|
|
5962
|
+
function middlewareErrorHandler(e, keyedResults) {
|
|
5963
|
+
Object.assign(keyedResults, {
|
|
5964
|
+
[e.routeId]: { type: "error", result: e.error }
|
|
5965
|
+
});
|
|
5966
|
+
}
|
|
5644
5967
|
function getSingleFetchDataStrategy(manifest, routeModules, getRouter) {
|
|
5645
|
-
return async (
|
|
5968
|
+
return async (args) => {
|
|
5969
|
+
let { request, matches, fetcherKey } = args;
|
|
5646
5970
|
if (request.method !== "GET") {
|
|
5647
|
-
return
|
|
5971
|
+
return runMiddlewarePipeline(
|
|
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
|
+
);
|
|
5648
5981
|
}
|
|
5649
5982
|
if (fetcherKey) {
|
|
5650
|
-
return
|
|
5983
|
+
return runMiddlewarePipeline(
|
|
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
|
+
);
|
|
5651
5996
|
}
|
|
5652
|
-
|
|
5997
|
+
let lowestLoadingIndex = getLowestLoadingIndex(
|
|
5653
5998
|
manifest,
|
|
5654
5999
|
routeModules,
|
|
5655
6000
|
getRouter(),
|
|
5656
|
-
request,
|
|
5657
6001
|
matches
|
|
5658
6002
|
);
|
|
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
|
+
);
|
|
5659
6019
|
};
|
|
5660
6020
|
}
|
|
5661
6021
|
async function singleFetchActionStrategy(request, matches) {
|
|
@@ -5685,6 +6045,20 @@ async function singleFetchActionStrategy(request, matches) {
|
|
|
5685
6045
|
}
|
|
5686
6046
|
};
|
|
5687
6047
|
}
|
|
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
|
+
}
|
|
5688
6062
|
async function singleFetchLoaderNavigationStrategy(manifest, routeModules, router, request, matches) {
|
|
5689
6063
|
let routesParams = /* @__PURE__ */ new Set();
|
|
5690
6064
|
let foundOptOutRoute = false;
|
|
@@ -5703,7 +6077,7 @@ async function singleFetchLoaderNavigationStrategy(manifest, routeModules, route
|
|
|
5703
6077
|
if (!router.state.initialized) {
|
|
5704
6078
|
return;
|
|
5705
6079
|
}
|
|
5706
|
-
if (
|
|
6080
|
+
if (isOptedOut(manifestRoute, routeModules[m.route.id], m, router)) {
|
|
5707
6081
|
foundOptOutRoute = true;
|
|
5708
6082
|
return;
|
|
5709
6083
|
}
|
|
@@ -5817,6 +6191,14 @@ async function fetchAndDecode(url, init) {
|
|
|
5817
6191
|
if (res.status === 404 && !res.headers.has("X-Remix-Response")) {
|
|
5818
6192
|
throw new ErrorResponseImpl(404, "Not Found", true);
|
|
5819
6193
|
}
|
|
6194
|
+
const NO_BODY_STATUS_CODES2 = /* @__PURE__ */ new Set([100, 101, 204, 205]);
|
|
6195
|
+
if (NO_BODY_STATUS_CODES2.has(res.status)) {
|
|
6196
|
+
if (!init.method || init.method === "GET") {
|
|
6197
|
+
return { status: res.status, data: {} };
|
|
6198
|
+
} else {
|
|
6199
|
+
return { status: res.status, data: { data: void 0 } };
|
|
6200
|
+
}
|
|
6201
|
+
}
|
|
5820
6202
|
invariant2(res.body, "No response body to decode");
|
|
5821
6203
|
try {
|
|
5822
6204
|
let decoded = await decodeViaTurboStream(res.body, window);
|
|
@@ -6095,8 +6477,8 @@ function createServerRoutes(manifest, routeModules, future, isSpaMode, parentId
|
|
|
6095
6477
|
// render, so just give it a no-op function so we can render down to the
|
|
6096
6478
|
// proper fallback
|
|
6097
6479
|
loader: route.hasLoader || route.hasClientLoader ? () => null : void 0
|
|
6098
|
-
// We don't need action/shouldRevalidate on these routes since
|
|
6099
|
-
// for a static render
|
|
6480
|
+
// We don't need middleware/action/shouldRevalidate on these routes since
|
|
6481
|
+
// they're for a static render
|
|
6100
6482
|
};
|
|
6101
6483
|
let children = createServerRoutes(
|
|
6102
6484
|
manifest,
|
|
@@ -6162,21 +6544,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6162
6544
|
}
|
|
6163
6545
|
return fetchServerHandler(singleFetch);
|
|
6164
6546
|
}
|
|
6165
|
-
function prefetchModule(modulePath) {
|
|
6166
|
-
import(
|
|
6167
|
-
/* @vite-ignore */
|
|
6168
|
-
/* webpackIgnore: true */
|
|
6169
|
-
modulePath
|
|
6170
|
-
);
|
|
6171
|
-
}
|
|
6172
|
-
function prefetchRouteModuleChunks(route2) {
|
|
6173
|
-
if (route2.clientActionModule) {
|
|
6174
|
-
prefetchModule(route2.clientActionModule);
|
|
6175
|
-
}
|
|
6176
|
-
if (route2.clientLoaderModule) {
|
|
6177
|
-
prefetchModule(route2.clientLoaderModule);
|
|
6178
|
-
}
|
|
6179
|
-
}
|
|
6180
6547
|
async function prefetchStylesAndCallHandler(handler) {
|
|
6181
6548
|
let cachedModule = routeModulesCache[route.id];
|
|
6182
6549
|
let linkPrefetchPromise = cachedModule ? prefetchStyleLinks(route, cachedModule) : Promise.resolve();
|
|
@@ -6195,6 +6562,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6195
6562
|
Object.assign(dataRoute, {
|
|
6196
6563
|
...dataRoute,
|
|
6197
6564
|
...getRouteComponents(route, routeModule, isSpaMode),
|
|
6565
|
+
middleware: routeModule.clientMiddleware,
|
|
6198
6566
|
handle: routeModule.handle,
|
|
6199
6567
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
6200
6568
|
routeModule,
|
|
@@ -6207,7 +6575,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6207
6575
|
let hasInitialError = initialState && initialState.errors && route.id in initialState.errors;
|
|
6208
6576
|
let initialError = hasInitialError ? initialState?.errors?.[route.id] : void 0;
|
|
6209
6577
|
let isHydrationRequest = needsRevalidation == null && (routeModule.clientLoader?.hydrate === true || !route.hasLoader);
|
|
6210
|
-
dataRoute.loader = async ({ request, params }, singleFetch) => {
|
|
6578
|
+
dataRoute.loader = async ({ request, params, context }, singleFetch) => {
|
|
6211
6579
|
try {
|
|
6212
6580
|
let result = await prefetchStylesAndCallHandler(async () => {
|
|
6213
6581
|
invariant2(
|
|
@@ -6221,6 +6589,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6221
6589
|
return routeModule.clientLoader({
|
|
6222
6590
|
request,
|
|
6223
6591
|
params,
|
|
6592
|
+
context,
|
|
6224
6593
|
async serverLoader() {
|
|
6225
6594
|
preventInvalidServerHandlerCall("loader", route, isSpaMode);
|
|
6226
6595
|
if (isHydrationRequest) {
|
|
@@ -6245,7 +6614,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6245
6614
|
routeModule,
|
|
6246
6615
|
isSpaMode
|
|
6247
6616
|
);
|
|
6248
|
-
dataRoute.action = ({ request, params }, singleFetch) => {
|
|
6617
|
+
dataRoute.action = ({ request, params, context }, singleFetch) => {
|
|
6249
6618
|
return prefetchStylesAndCallHandler(async () => {
|
|
6250
6619
|
invariant2(
|
|
6251
6620
|
routeModule,
|
|
@@ -6260,6 +6629,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6260
6629
|
return routeModule.clientAction({
|
|
6261
6630
|
request,
|
|
6262
6631
|
params,
|
|
6632
|
+
context,
|
|
6263
6633
|
async serverAction() {
|
|
6264
6634
|
preventInvalidServerHandlerCall("action", route, isSpaMode);
|
|
6265
6635
|
return fetchServerAction(singleFetch);
|
|
@@ -6269,64 +6639,26 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6269
6639
|
};
|
|
6270
6640
|
} else {
|
|
6271
6641
|
if (!route.hasClientLoader) {
|
|
6272
|
-
dataRoute.loader = (
|
|
6642
|
+
dataRoute.loader = (_, singleFetch) => prefetchStylesAndCallHandler(() => {
|
|
6273
6643
|
if (isSpaMode) return Promise.resolve(null);
|
|
6274
6644
|
return fetchServerLoader(singleFetch);
|
|
6275
6645
|
});
|
|
6276
|
-
} else if (route.clientLoaderModule) {
|
|
6277
|
-
dataRoute.loader = async (args, singleFetch) => {
|
|
6278
|
-
invariant2(route.clientLoaderModule);
|
|
6279
|
-
let { clientLoader } = await import(
|
|
6280
|
-
/* @vite-ignore */
|
|
6281
|
-
/* webpackIgnore: true */
|
|
6282
|
-
route.clientLoaderModule
|
|
6283
|
-
);
|
|
6284
|
-
return clientLoader({
|
|
6285
|
-
...args,
|
|
6286
|
-
async serverLoader() {
|
|
6287
|
-
preventInvalidServerHandlerCall("loader", route, isSpaMode);
|
|
6288
|
-
return fetchServerLoader(singleFetch);
|
|
6289
|
-
}
|
|
6290
|
-
});
|
|
6291
|
-
};
|
|
6292
6646
|
}
|
|
6293
6647
|
if (!route.hasClientAction) {
|
|
6294
|
-
dataRoute.action = (
|
|
6648
|
+
dataRoute.action = (_, singleFetch) => prefetchStylesAndCallHandler(() => {
|
|
6295
6649
|
if (isSpaMode) {
|
|
6296
6650
|
throw noActionDefinedError("clientAction", route.id);
|
|
6297
6651
|
}
|
|
6298
6652
|
return fetchServerAction(singleFetch);
|
|
6299
6653
|
});
|
|
6300
|
-
} else if (route.clientActionModule) {
|
|
6301
|
-
dataRoute.action = async (args, singleFetch) => {
|
|
6302
|
-
invariant2(route.clientActionModule);
|
|
6303
|
-
prefetchRouteModuleChunks(route);
|
|
6304
|
-
let { clientAction } = await import(
|
|
6305
|
-
/* @vite-ignore */
|
|
6306
|
-
/* webpackIgnore: true */
|
|
6307
|
-
route.clientActionModule
|
|
6308
|
-
);
|
|
6309
|
-
return clientAction({
|
|
6310
|
-
...args,
|
|
6311
|
-
async serverAction() {
|
|
6312
|
-
preventInvalidServerHandlerCall("action", route, isSpaMode);
|
|
6313
|
-
return fetchServerAction(singleFetch);
|
|
6314
|
-
}
|
|
6315
|
-
});
|
|
6316
|
-
};
|
|
6317
6654
|
}
|
|
6318
6655
|
dataRoute.lazy = async () => {
|
|
6319
|
-
|
|
6320
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
6321
|
-
}
|
|
6322
|
-
let modPromise = loadRouteModuleWithBlockingLinks(
|
|
6656
|
+
let mod = await loadRouteModuleWithBlockingLinks(
|
|
6323
6657
|
route,
|
|
6324
6658
|
routeModulesCache
|
|
6325
6659
|
);
|
|
6326
|
-
prefetchRouteModuleChunks(route);
|
|
6327
|
-
let mod = await modPromise;
|
|
6328
6660
|
let lazyRoute = { ...mod };
|
|
6329
|
-
if (mod.clientLoader
|
|
6661
|
+
if (mod.clientLoader) {
|
|
6330
6662
|
let clientLoader = mod.clientLoader;
|
|
6331
6663
|
lazyRoute.loader = (args, singleFetch) => clientLoader({
|
|
6332
6664
|
...args,
|
|
@@ -6336,7 +6668,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6336
6668
|
}
|
|
6337
6669
|
});
|
|
6338
6670
|
}
|
|
6339
|
-
if (mod.clientAction
|
|
6671
|
+
if (mod.clientAction) {
|
|
6340
6672
|
let clientAction = mod.clientAction;
|
|
6341
6673
|
lazyRoute.action = (args, singleFetch) => clientAction({
|
|
6342
6674
|
...args,
|
|
@@ -6349,6 +6681,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
|
|
|
6349
6681
|
return {
|
|
6350
6682
|
...lazyRoute.loader ? { loader: lazyRoute.loader } : {},
|
|
6351
6683
|
...lazyRoute.action ? { action: lazyRoute.action } : {},
|
|
6684
|
+
middleware: mod.clientMiddleware,
|
|
6352
6685
|
hasErrorBoundary: lazyRoute.hasErrorBoundary,
|
|
6353
6686
|
shouldRevalidate: getShouldRevalidateFunction(
|
|
6354
6687
|
lazyRoute,
|
|
@@ -6406,6 +6739,7 @@ async function loadRouteModuleWithBlockingLinks(route, routeModules) {
|
|
|
6406
6739
|
return {
|
|
6407
6740
|
Component: getRouteModuleComponent(routeModule),
|
|
6408
6741
|
ErrorBoundary: routeModule.ErrorBoundary,
|
|
6742
|
+
clientMiddleware: routeModule.clientMiddleware,
|
|
6409
6743
|
clientAction: routeModule.clientAction,
|
|
6410
6744
|
clientLoader: routeModule.clientLoader,
|
|
6411
6745
|
handle: routeModule.handle,
|
|
@@ -6485,12 +6819,13 @@ function useFogOFWarDiscovery(router, manifest, routeModules, isSpaMode) {
|
|
|
6485
6819
|
if (!path) {
|
|
6486
6820
|
return;
|
|
6487
6821
|
}
|
|
6488
|
-
let
|
|
6489
|
-
if (!discoveredPaths.has(
|
|
6490
|
-
nextPaths.add(
|
|
6822
|
+
let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
|
|
6823
|
+
if (!discoveredPaths.has(pathname)) {
|
|
6824
|
+
nextPaths.add(pathname);
|
|
6491
6825
|
}
|
|
6492
6826
|
}
|
|
6493
6827
|
async function fetchPatches() {
|
|
6828
|
+
document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
|
|
6494
6829
|
let lazyPaths = Array.from(nextPaths.keys()).filter((path) => {
|
|
6495
6830
|
if (discoveredPaths.has(path)) {
|
|
6496
6831
|
nextPaths.delete(path);
|
|
@@ -6514,30 +6849,9 @@ function useFogOFWarDiscovery(router, manifest, routeModules, isSpaMode) {
|
|
|
6514
6849
|
console.error("Failed to fetch manifest patches", e);
|
|
6515
6850
|
}
|
|
6516
6851
|
}
|
|
6517
|
-
document.body.querySelectorAll("a[data-discover], form[data-discover]").forEach((el) => registerElement(el));
|
|
6518
|
-
fetchPatches();
|
|
6519
6852
|
let debouncedFetchPatches = debounce(fetchPatches, 100);
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
}
|
|
6523
|
-
let observer = new MutationObserver((records) => {
|
|
6524
|
-
let elements = /* @__PURE__ */ new Set();
|
|
6525
|
-
records.forEach((r) => {
|
|
6526
|
-
[r.target, ...r.addedNodes].forEach((node) => {
|
|
6527
|
-
if (!isElement(node)) return;
|
|
6528
|
-
if (node.tagName === "A" && node.getAttribute("data-discover")) {
|
|
6529
|
-
elements.add(node);
|
|
6530
|
-
} else if (node.tagName === "FORM" && node.getAttribute("data-discover")) {
|
|
6531
|
-
elements.add(node);
|
|
6532
|
-
}
|
|
6533
|
-
if (node.tagName !== "A") {
|
|
6534
|
-
node.querySelectorAll("a[data-discover], form[data-discover]").forEach((el) => elements.add(el));
|
|
6535
|
-
}
|
|
6536
|
-
});
|
|
6537
|
-
});
|
|
6538
|
-
elements.forEach((el) => registerElement(el));
|
|
6539
|
-
debouncedFetchPatches();
|
|
6540
|
-
});
|
|
6853
|
+
fetchPatches();
|
|
6854
|
+
let observer = new MutationObserver(() => debouncedFetchPatches());
|
|
6541
6855
|
observer.observe(document.documentElement, {
|
|
6542
6856
|
subtree: true,
|
|
6543
6857
|
childList: true,
|
|
@@ -6948,44 +7262,11 @@ function Scripts(props) {
|
|
|
6948
7262
|
let streamScript = "window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());";
|
|
6949
7263
|
let contextScript = staticContext ? `window.__reactRouterContext = ${serverHandoffString};${streamScript}` : " ";
|
|
6950
7264
|
let routeModulesScript = !isStatic ? " " : `${manifest.hmr?.runtime ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
|
|
6951
|
-
${matches.map(
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
clientActionModule,
|
|
6957
|
-
clientLoaderModule,
|
|
6958
|
-
hydrateFallbackModule,
|
|
6959
|
-
module
|
|
6960
|
-
} = manifestEntry;
|
|
6961
|
-
let chunks = [
|
|
6962
|
-
...clientActionModule ? [
|
|
6963
|
-
{
|
|
6964
|
-
module: clientActionModule,
|
|
6965
|
-
varName: `${routeVarName}_clientAction`
|
|
6966
|
-
}
|
|
6967
|
-
] : [],
|
|
6968
|
-
...clientLoaderModule ? [
|
|
6969
|
-
{
|
|
6970
|
-
module: clientLoaderModule,
|
|
6971
|
-
varName: `${routeVarName}_clientLoader`
|
|
6972
|
-
}
|
|
6973
|
-
] : [],
|
|
6974
|
-
...hydrateFallbackModule ? [
|
|
6975
|
-
{
|
|
6976
|
-
module: hydrateFallbackModule,
|
|
6977
|
-
varName: `${routeVarName}_HydrateFallback`
|
|
6978
|
-
}
|
|
6979
|
-
] : [],
|
|
6980
|
-
{ module, varName: `${routeVarName}_main` }
|
|
6981
|
-
];
|
|
6982
|
-
if (chunks.length === 1) {
|
|
6983
|
-
return `import * as ${routeVarName} from ${JSON.stringify(module)};`;
|
|
6984
|
-
}
|
|
6985
|
-
let chunkImportsSnippet = chunks.map((chunk) => `import * as ${chunk.varName} from "${chunk.module}";`).join("\n");
|
|
6986
|
-
let mergedChunksSnippet = `const ${routeVarName} = {${chunks.map((chunk) => `...${chunk.varName}`).join(",")}};`;
|
|
6987
|
-
return [chunkImportsSnippet, mergedChunksSnippet].join("\n");
|
|
6988
|
-
}).join("\n")}
|
|
7265
|
+
${matches.map(
|
|
7266
|
+
(match, index) => `import * as route${index} from ${JSON.stringify(
|
|
7267
|
+
manifest.routes[match.route.id].module
|
|
7268
|
+
)};`
|
|
7269
|
+
).join("\n")}
|
|
6989
7270
|
${enableFogOfWar ? (
|
|
6990
7271
|
// Inline a minimal manifest with the SSR matches
|
|
6991
7272
|
`window.__reactRouterManifest = ${JSON.stringify(
|
|
@@ -7016,11 +7297,11 @@ import(${JSON.stringify(manifest.entry.module)});`;
|
|
|
7016
7297
|
}
|
|
7017
7298
|
));
|
|
7018
7299
|
}, []);
|
|
7019
|
-
let
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
);
|
|
7300
|
+
let routePreloads = matches.map((match) => {
|
|
7301
|
+
let route = manifest.routes[match.route.id];
|
|
7302
|
+
return route ? (route.imports || []).concat([route.module]) : [];
|
|
7303
|
+
}).flat(1);
|
|
7304
|
+
let preloads = isHydrated ? [] : manifest.entry.imports.concat(routePreloads);
|
|
7024
7305
|
return isHydrated ? null : /* @__PURE__ */ React9.createElement(React9.Fragment, null, !enableFogOfWar ? /* @__PURE__ */ React9.createElement(
|
|
7025
7306
|
"link",
|
|
7026
7307
|
{
|
|
@@ -7064,13 +7345,14 @@ function mergeRefs(...refs) {
|
|
|
7064
7345
|
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
7065
7346
|
try {
|
|
7066
7347
|
if (isBrowser) {
|
|
7067
|
-
window.__reactRouterVersion = "0.0.0-experimental-
|
|
7348
|
+
window.__reactRouterVersion = "0.0.0-experimental-beaa4f52a";
|
|
7068
7349
|
}
|
|
7069
7350
|
} catch (e) {
|
|
7070
7351
|
}
|
|
7071
7352
|
function createBrowserRouter(routes, opts) {
|
|
7072
7353
|
return createRouter({
|
|
7073
7354
|
basename: opts?.basename,
|
|
7355
|
+
context: opts?.context,
|
|
7074
7356
|
future: opts?.future,
|
|
7075
7357
|
history: createBrowserHistory({ window: opts?.window }),
|
|
7076
7358
|
hydrationData: opts?.hydrationData || parseHydrationData(),
|
|
@@ -7084,6 +7366,7 @@ function createBrowserRouter(routes, opts) {
|
|
|
7084
7366
|
function createHashRouter(routes, opts) {
|
|
7085
7367
|
return createRouter({
|
|
7086
7368
|
basename: opts?.basename,
|
|
7369
|
+
context: opts?.context,
|
|
7087
7370
|
future: opts?.future,
|
|
7088
7371
|
history: createHashHistory({ window: opts?.window }),
|
|
7089
7372
|
hydrationData: opts?.hydrationData || parseHydrationData(),
|
|
@@ -8225,13 +8508,14 @@ function createRoutesStub(routes, context = {}) {
|
|
|
8225
8508
|
isSpaMode: false
|
|
8226
8509
|
};
|
|
8227
8510
|
let patched = processRoutes(
|
|
8228
|
-
// @ts-expect-error
|
|
8511
|
+
// @ts-expect-error `StubRouteObject` is stricter about `loader`/`action`
|
|
8512
|
+
// types compared to `AgnosticRouteObject`
|
|
8229
8513
|
convertRoutesToDataRoutes(routes, (r) => r),
|
|
8230
|
-
context,
|
|
8231
8514
|
remixContextRef.current.manifest,
|
|
8232
8515
|
remixContextRef.current.routeModules
|
|
8233
8516
|
);
|
|
8234
8517
|
routerRef.current = createMemoryRouter(patched, {
|
|
8518
|
+
context,
|
|
8235
8519
|
initialEntries,
|
|
8236
8520
|
initialIndex,
|
|
8237
8521
|
hydrationData
|
|
@@ -8240,14 +8524,13 @@ function createRoutesStub(routes, context = {}) {
|
|
|
8240
8524
|
return /* @__PURE__ */ React13.createElement(FrameworkContext.Provider, { value: remixContextRef.current }, /* @__PURE__ */ React13.createElement(RouterProvider, { router: routerRef.current }));
|
|
8241
8525
|
};
|
|
8242
8526
|
}
|
|
8243
|
-
function processRoutes(routes,
|
|
8527
|
+
function processRoutes(routes, manifest, routeModules, parentId) {
|
|
8244
8528
|
return routes.map((route) => {
|
|
8245
8529
|
if (!route.id) {
|
|
8246
8530
|
throw new Error(
|
|
8247
8531
|
"Expected a route.id in @remix-run/testing processRoutes() function"
|
|
8248
8532
|
);
|
|
8249
8533
|
}
|
|
8250
|
-
let { loader, action } = route;
|
|
8251
8534
|
let newRoute = {
|
|
8252
8535
|
id: route.id,
|
|
8253
8536
|
path: route.path,
|
|
@@ -8255,8 +8538,8 @@ function processRoutes(routes, context, manifest, routeModules, parentId) {
|
|
|
8255
8538
|
Component: route.Component,
|
|
8256
8539
|
HydrateFallback: route.HydrateFallback,
|
|
8257
8540
|
ErrorBoundary: route.ErrorBoundary,
|
|
8258
|
-
action: action
|
|
8259
|
-
loader: loader
|
|
8541
|
+
action: route.action,
|
|
8542
|
+
loader: route.loader,
|
|
8260
8543
|
handle: route.handle,
|
|
8261
8544
|
shouldRevalidate: route.shouldRevalidate
|
|
8262
8545
|
};
|
|
@@ -8273,11 +8556,8 @@ function processRoutes(routes, context, manifest, routeModules, parentId) {
|
|
|
8273
8556
|
hasClientAction: false,
|
|
8274
8557
|
hasClientLoader: false,
|
|
8275
8558
|
hasErrorBoundary: route.ErrorBoundary != null,
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
clientActionModule: void 0,
|
|
8279
|
-
clientLoaderModule: void 0,
|
|
8280
|
-
hydrateFallbackModule: void 0
|
|
8559
|
+
module: "build/stub-path-to-module.js"
|
|
8560
|
+
// any need for this?
|
|
8281
8561
|
};
|
|
8282
8562
|
manifest.routes[newRoute.id] = entryRoute;
|
|
8283
8563
|
routeModules[route.id] = {
|
|
@@ -8291,7 +8571,6 @@ function processRoutes(routes, context, manifest, routeModules, parentId) {
|
|
|
8291
8571
|
if (route.children) {
|
|
8292
8572
|
newRoute.children = processRoutes(
|
|
8293
8573
|
route.children,
|
|
8294
|
-
context,
|
|
8295
8574
|
manifest,
|
|
8296
8575
|
routeModules,
|
|
8297
8576
|
newRoute.id
|
|
@@ -8652,6 +8931,7 @@ function createStaticHandlerDataRoutes(manifest, future, parentId = "", routesBy
|
|
|
8652
8931
|
hasErrorBoundary: route.id === "root" || route.module.ErrorBoundary != null,
|
|
8653
8932
|
id: route.id,
|
|
8654
8933
|
path: route.path,
|
|
8934
|
+
middleware: route.module.middleware,
|
|
8655
8935
|
// Need to use RR's version in the param typed here to permit the optional
|
|
8656
8936
|
// context even though we know it'll always be provided in remix
|
|
8657
8937
|
loader: route.module.loader ? async (args) => {
|
|
@@ -8794,25 +9074,8 @@ function prependCookies(parentHeaders, childHeaders) {
|
|
|
8794
9074
|
}
|
|
8795
9075
|
|
|
8796
9076
|
// lib/server-runtime/single-fetch.ts
|
|
9077
|
+
var NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([100, 101, 204, 205, 304]);
|
|
8797
9078
|
var SINGLE_FETCH_REDIRECT_STATUS = 202;
|
|
8798
|
-
function getSingleFetchDataStrategy2({
|
|
8799
|
-
isActionDataRequest,
|
|
8800
|
-
loadRouteIds
|
|
8801
|
-
} = {}) {
|
|
8802
|
-
return async ({ request, matches }) => {
|
|
8803
|
-
if (isActionDataRequest && request.method === "GET") {
|
|
8804
|
-
return {};
|
|
8805
|
-
}
|
|
8806
|
-
let matchesToLoad = loadRouteIds ? matches.filter((m) => loadRouteIds.includes(m.route.id)) : matches;
|
|
8807
|
-
let results = await Promise.all(
|
|
8808
|
-
matchesToLoad.map((match) => match.resolve())
|
|
8809
|
-
);
|
|
8810
|
-
return results.reduce(
|
|
8811
|
-
(acc, result, i) => Object.assign(acc, { [matchesToLoad[i].route.id]: result }),
|
|
8812
|
-
{}
|
|
8813
|
-
);
|
|
8814
|
-
};
|
|
8815
|
-
}
|
|
8816
9079
|
async function singleFetchAction(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
|
|
8817
9080
|
try {
|
|
8818
9081
|
let handlerRequest = new Request(handlerUrl, {
|
|
@@ -8825,12 +9088,46 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
|
|
|
8825
9088
|
let result = await staticHandler.query(handlerRequest, {
|
|
8826
9089
|
requestContext: loadContext,
|
|
8827
9090
|
skipLoaderErrorBubbling: true,
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
9091
|
+
skipRevalidation: true,
|
|
9092
|
+
async respond(context) {
|
|
9093
|
+
let headers = getDocumentHeaders(build, context);
|
|
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
|
+
}
|
|
8831
9127
|
});
|
|
8832
|
-
|
|
8833
|
-
|
|
9128
|
+
invariant3(isResponse(result), "Expected a Response from query()");
|
|
9129
|
+
if (isRedirectResponse(result)) {
|
|
9130
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
8834
9131
|
result: getSingleFetchRedirect(
|
|
8835
9132
|
result.status,
|
|
8836
9133
|
result.headers,
|
|
@@ -8838,47 +9135,16 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
|
|
|
8838
9135
|
),
|
|
8839
9136
|
headers: result.headers,
|
|
8840
9137
|
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
8841
|
-
};
|
|
8842
|
-
}
|
|
8843
|
-
let context = result;
|
|
8844
|
-
let headers = getDocumentHeaders(build, context);
|
|
8845
|
-
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
8846
|
-
return {
|
|
8847
|
-
result: getSingleFetchRedirect(
|
|
8848
|
-
context.statusCode,
|
|
8849
|
-
headers,
|
|
8850
|
-
build.basename
|
|
8851
|
-
),
|
|
8852
|
-
headers,
|
|
8853
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
8854
|
-
};
|
|
8855
|
-
}
|
|
8856
|
-
if (context.errors) {
|
|
8857
|
-
Object.values(context.errors).forEach((err) => {
|
|
8858
|
-
if (!isRouteErrorResponse(err) || err.error) {
|
|
8859
|
-
handleError(err);
|
|
8860
|
-
}
|
|
8861
9138
|
});
|
|
8862
|
-
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
8863
9139
|
}
|
|
8864
|
-
|
|
8865
|
-
if (context.errors) {
|
|
8866
|
-
singleFetchResult = { error: Object.values(context.errors)[0] };
|
|
8867
|
-
} else {
|
|
8868
|
-
singleFetchResult = { data: Object.values(context.actionData || {})[0] };
|
|
8869
|
-
}
|
|
8870
|
-
return {
|
|
8871
|
-
result: singleFetchResult,
|
|
8872
|
-
headers,
|
|
8873
|
-
status: context.statusCode
|
|
8874
|
-
};
|
|
9140
|
+
return result;
|
|
8875
9141
|
} catch (error) {
|
|
8876
9142
|
handleError(error);
|
|
8877
|
-
return {
|
|
9143
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
8878
9144
|
result: { error },
|
|
8879
9145
|
headers: new Headers(),
|
|
8880
9146
|
status: 500
|
|
8881
|
-
};
|
|
9147
|
+
});
|
|
8882
9148
|
}
|
|
8883
9149
|
}
|
|
8884
9150
|
async function singleFetchLoaders(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
|
|
@@ -8887,16 +9153,61 @@ async function singleFetchLoaders(build, serverMode, staticHandler, request, han
|
|
|
8887
9153
|
headers: request.headers,
|
|
8888
9154
|
signal: request.signal
|
|
8889
9155
|
});
|
|
8890
|
-
let
|
|
9156
|
+
let routesParam = new URL(request.url).searchParams.get("_routes");
|
|
9157
|
+
let loadRouteIds = routesParam ? new Set(routesParam.split(",")) : null;
|
|
8891
9158
|
let result = await staticHandler.query(handlerRequest, {
|
|
8892
9159
|
requestContext: loadContext,
|
|
9160
|
+
filterMatchesToLoad: (m) => !loadRouteIds || loadRouteIds.has(m.route.id),
|
|
8893
9161
|
skipLoaderErrorBubbling: true,
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
9162
|
+
async respond(context) {
|
|
9163
|
+
let headers = getDocumentHeaders(build, context);
|
|
9164
|
+
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
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
|
+
}
|
|
8897
9207
|
});
|
|
8898
|
-
|
|
8899
|
-
|
|
9208
|
+
invariant3(isResponse(result), "Expected a Response from query()");
|
|
9209
|
+
if (isRedirectResponse(result)) {
|
|
9210
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
8900
9211
|
result: {
|
|
8901
9212
|
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
8902
9213
|
result.status,
|
|
@@ -8906,57 +9217,42 @@ async function singleFetchLoaders(build, serverMode, staticHandler, request, han
|
|
|
8906
9217
|
},
|
|
8907
9218
|
headers: result.headers,
|
|
8908
9219
|
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
8909
|
-
};
|
|
8910
|
-
}
|
|
8911
|
-
let context = result;
|
|
8912
|
-
let headers = getDocumentHeaders(build, context);
|
|
8913
|
-
if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
|
|
8914
|
-
return {
|
|
8915
|
-
result: {
|
|
8916
|
-
[SingleFetchRedirectSymbol]: getSingleFetchRedirect(
|
|
8917
|
-
context.statusCode,
|
|
8918
|
-
headers,
|
|
8919
|
-
build.basename
|
|
8920
|
-
)
|
|
8921
|
-
},
|
|
8922
|
-
headers,
|
|
8923
|
-
status: SINGLE_FETCH_REDIRECT_STATUS
|
|
8924
|
-
};
|
|
8925
|
-
}
|
|
8926
|
-
if (context.errors) {
|
|
8927
|
-
Object.values(context.errors).forEach((err) => {
|
|
8928
|
-
if (!isRouteErrorResponse(err) || err.error) {
|
|
8929
|
-
handleError(err);
|
|
8930
|
-
}
|
|
8931
9220
|
});
|
|
8932
|
-
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
8933
9221
|
}
|
|
8934
|
-
|
|
8935
|
-
let loadedMatches = loadRouteIds ? context.matches.filter(
|
|
8936
|
-
(m) => m.route.loader && loadRouteIds.includes(m.route.id)
|
|
8937
|
-
) : context.matches;
|
|
8938
|
-
loadedMatches.forEach((m) => {
|
|
8939
|
-
let { id } = m.route;
|
|
8940
|
-
if (context.errors && context.errors.hasOwnProperty(id)) {
|
|
8941
|
-
results[id] = { error: context.errors[id] };
|
|
8942
|
-
} else if (context.loaderData.hasOwnProperty(id)) {
|
|
8943
|
-
results[id] = { data: context.loaderData[id] };
|
|
8944
|
-
}
|
|
8945
|
-
});
|
|
8946
|
-
return {
|
|
8947
|
-
result: results,
|
|
8948
|
-
headers,
|
|
8949
|
-
status: context.statusCode
|
|
8950
|
-
};
|
|
9222
|
+
return result;
|
|
8951
9223
|
} catch (error) {
|
|
8952
9224
|
handleError(error);
|
|
8953
|
-
return {
|
|
9225
|
+
return generateSingleFetchResponse(request, build, serverMode, {
|
|
8954
9226
|
result: { root: { error } },
|
|
8955
9227
|
headers: new Headers(),
|
|
8956
9228
|
status: 500
|
|
8957
|
-
};
|
|
9229
|
+
});
|
|
8958
9230
|
}
|
|
8959
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 });
|
|
9241
|
+
}
|
|
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
|
+
}
|
|
8960
9256
|
function getSingleFetchRedirect(status, headers, basename) {
|
|
8961
9257
|
let redirect2 = headers.get("Location");
|
|
8962
9258
|
if (basename) {
|
|
@@ -9197,7 +9493,7 @@ async function handleManifestRequest(build, routes, url) {
|
|
|
9197
9493
|
return new Response("Invalid Request", { status: 400 });
|
|
9198
9494
|
}
|
|
9199
9495
|
async function handleSingleFetchRequest(serverMode, build, staticHandler, request, handlerUrl, loadContext, handleError) {
|
|
9200
|
-
let
|
|
9496
|
+
let response = request.method !== "GET" ? await singleFetchAction(
|
|
9201
9497
|
build,
|
|
9202
9498
|
serverMode,
|
|
9203
9499
|
staticHandler,
|
|
@@ -9214,129 +9510,67 @@ async function handleSingleFetchRequest(serverMode, build, staticHandler, reques
|
|
|
9214
9510
|
loadContext,
|
|
9215
9511
|
handleError
|
|
9216
9512
|
);
|
|
9217
|
-
|
|
9218
|
-
resultHeaders.set("X-Remix-Response", "yes");
|
|
9219
|
-
if (status === 304) {
|
|
9220
|
-
return new Response(null, { status: 304, headers: resultHeaders });
|
|
9221
|
-
}
|
|
9222
|
-
resultHeaders.set("Content-Type", "text/x-script");
|
|
9223
|
-
return new Response(
|
|
9224
|
-
encodeViaTurboStream(
|
|
9225
|
-
result,
|
|
9226
|
-
request.signal,
|
|
9227
|
-
build.entry.module.streamTimeout,
|
|
9228
|
-
serverMode
|
|
9229
|
-
),
|
|
9230
|
-
{
|
|
9231
|
-
status: status || 200,
|
|
9232
|
-
headers: resultHeaders
|
|
9233
|
-
}
|
|
9234
|
-
);
|
|
9513
|
+
return response;
|
|
9235
9514
|
}
|
|
9236
9515
|
async function handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, criticalCss) {
|
|
9237
|
-
let context;
|
|
9238
9516
|
try {
|
|
9239
|
-
|
|
9240
|
-
requestContext: loadContext
|
|
9517
|
+
let response = await staticHandler.query(request, {
|
|
9518
|
+
requestContext: loadContext,
|
|
9519
|
+
respond: renderHtml
|
|
9241
9520
|
});
|
|
9521
|
+
invariant3(
|
|
9522
|
+
isResponse(response),
|
|
9523
|
+
"Expected a Response to be returned from query"
|
|
9524
|
+
);
|
|
9525
|
+
return response;
|
|
9242
9526
|
} catch (error) {
|
|
9243
9527
|
handleError(error);
|
|
9244
9528
|
return new Response(null, { status: 500 });
|
|
9245
9529
|
}
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
if (context.errors) {
|
|
9254
|
-
Object.values(context.errors).forEach((err) => {
|
|
9255
|
-
if (!isRouteErrorResponse(err) || err.error) {
|
|
9256
|
-
handleError(err);
|
|
9257
|
-
}
|
|
9258
|
-
});
|
|
9259
|
-
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9260
|
-
}
|
|
9261
|
-
let state = {
|
|
9262
|
-
loaderData: context.loaderData,
|
|
9263
|
-
actionData: context.actionData,
|
|
9264
|
-
errors: serializeErrors2(context.errors, serverMode)
|
|
9265
|
-
};
|
|
9266
|
-
let entryContext = {
|
|
9267
|
-
manifest: build.assets,
|
|
9268
|
-
routeModules: createEntryRouteModules(build.routes),
|
|
9269
|
-
staticHandlerContext: context,
|
|
9270
|
-
criticalCss,
|
|
9271
|
-
serverHandoffString: createServerHandoffString({
|
|
9272
|
-
basename: build.basename,
|
|
9273
|
-
criticalCss,
|
|
9274
|
-
future: build.future,
|
|
9275
|
-
isSpaMode: build.isSpaMode
|
|
9276
|
-
}),
|
|
9277
|
-
serverHandoffStream: encodeViaTurboStream(
|
|
9278
|
-
state,
|
|
9279
|
-
request.signal,
|
|
9280
|
-
build.entry.module.streamTimeout,
|
|
9281
|
-
serverMode
|
|
9282
|
-
),
|
|
9283
|
-
renderMeta: {},
|
|
9284
|
-
future: build.future,
|
|
9285
|
-
isSpaMode: build.isSpaMode,
|
|
9286
|
-
serializeError: (err) => serializeError(err, serverMode)
|
|
9287
|
-
};
|
|
9288
|
-
let handleDocumentRequestFunction = build.entry.module.default;
|
|
9289
|
-
try {
|
|
9290
|
-
return await handleDocumentRequestFunction(
|
|
9291
|
-
request,
|
|
9292
|
-
context.statusCode,
|
|
9293
|
-
headers,
|
|
9294
|
-
entryContext,
|
|
9295
|
-
loadContext
|
|
9296
|
-
);
|
|
9297
|
-
} catch (error) {
|
|
9298
|
-
handleError(error);
|
|
9299
|
-
let errorForSecondRender = error;
|
|
9300
|
-
if (isResponse(error)) {
|
|
9301
|
-
try {
|
|
9302
|
-
let data2 = await unwrapResponse(error);
|
|
9303
|
-
errorForSecondRender = new ErrorResponseImpl(
|
|
9304
|
-
error.status,
|
|
9305
|
-
error.statusText,
|
|
9306
|
-
data2
|
|
9307
|
-
);
|
|
9308
|
-
} catch (e) {
|
|
9309
|
-
}
|
|
9530
|
+
async function renderHtml(context) {
|
|
9531
|
+
if (isResponse(context)) {
|
|
9532
|
+
return context;
|
|
9533
|
+
}
|
|
9534
|
+
let headers = getDocumentHeaders(build, context);
|
|
9535
|
+
if (NO_BODY_STATUS_CODES.has(context.statusCode)) {
|
|
9536
|
+
return new Response(null, { status: context.statusCode, headers });
|
|
9310
9537
|
}
|
|
9311
|
-
context = getStaticContextFromError(
|
|
9312
|
-
staticHandler.dataRoutes,
|
|
9313
|
-
context,
|
|
9314
|
-
errorForSecondRender
|
|
9315
|
-
);
|
|
9316
9538
|
if (context.errors) {
|
|
9539
|
+
Object.values(context.errors).forEach((err) => {
|
|
9540
|
+
if (!isRouteErrorResponse(err) || err.error) {
|
|
9541
|
+
handleError(err);
|
|
9542
|
+
}
|
|
9543
|
+
});
|
|
9317
9544
|
context.errors = sanitizeErrors(context.errors, serverMode);
|
|
9318
9545
|
}
|
|
9319
|
-
let
|
|
9546
|
+
let state = {
|
|
9320
9547
|
loaderData: context.loaderData,
|
|
9321
9548
|
actionData: context.actionData,
|
|
9322
9549
|
errors: serializeErrors2(context.errors, serverMode)
|
|
9323
9550
|
};
|
|
9324
|
-
entryContext = {
|
|
9325
|
-
|
|
9551
|
+
let entryContext = {
|
|
9552
|
+
manifest: build.assets,
|
|
9553
|
+
routeModules: createEntryRouteModules(build.routes),
|
|
9326
9554
|
staticHandlerContext: context,
|
|
9555
|
+
criticalCss,
|
|
9327
9556
|
serverHandoffString: createServerHandoffString({
|
|
9328
9557
|
basename: build.basename,
|
|
9558
|
+
criticalCss,
|
|
9329
9559
|
future: build.future,
|
|
9330
9560
|
isSpaMode: build.isSpaMode
|
|
9331
9561
|
}),
|
|
9332
9562
|
serverHandoffStream: encodeViaTurboStream(
|
|
9333
|
-
|
|
9563
|
+
state,
|
|
9334
9564
|
request.signal,
|
|
9335
9565
|
build.entry.module.streamTimeout,
|
|
9336
9566
|
serverMode
|
|
9337
9567
|
),
|
|
9338
|
-
renderMeta: {}
|
|
9568
|
+
renderMeta: {},
|
|
9569
|
+
future: build.future,
|
|
9570
|
+
isSpaMode: build.isSpaMode,
|
|
9571
|
+
serializeError: (err) => serializeError(err, serverMode)
|
|
9339
9572
|
};
|
|
9573
|
+
let handleDocumentRequestFunction = build.entry.module.default;
|
|
9340
9574
|
try {
|
|
9341
9575
|
return await handleDocumentRequestFunction(
|
|
9342
9576
|
request,
|
|
@@ -9345,9 +9579,61 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
|
|
|
9345
9579
|
entryContext,
|
|
9346
9580
|
loadContext
|
|
9347
9581
|
);
|
|
9348
|
-
} catch (
|
|
9349
|
-
handleError(
|
|
9350
|
-
|
|
9582
|
+
} catch (error) {
|
|
9583
|
+
handleError(error);
|
|
9584
|
+
let errorForSecondRender = error;
|
|
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
9637
|
}
|
|
9352
9638
|
}
|
|
9353
9639
|
}
|
|
@@ -9355,7 +9641,10 @@ async function handleResourceRequest(serverMode, staticHandler, routeId, request
|
|
|
9355
9641
|
try {
|
|
9356
9642
|
let response = await staticHandler.queryRoute(request, {
|
|
9357
9643
|
routeId,
|
|
9358
|
-
requestContext: loadContext
|
|
9644
|
+
requestContext: loadContext,
|
|
9645
|
+
async respond(ctx) {
|
|
9646
|
+
return ctx;
|
|
9647
|
+
}
|
|
9359
9648
|
});
|
|
9360
9649
|
invariant3(
|
|
9361
9650
|
isResponse(response),
|
|
@@ -9373,6 +9662,13 @@ async function handleResourceRequest(serverMode, staticHandler, routeId, request
|
|
|
9373
9662
|
}
|
|
9374
9663
|
return errorResponseToJson(error, serverMode);
|
|
9375
9664
|
}
|
|
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
|
+
}
|
|
9376
9672
|
handleError(error);
|
|
9377
9673
|
return returnLastResortErrorResponse(error, serverMode);
|
|
9378
9674
|
}
|