@remix-run/router 0.0.0-experimental-35fa15e5 → 0.0.0-experimental-8bb3ffdf
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 +200 -0
- package/README.md +1 -1
- package/dist/router.cjs.js +124 -103
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +8 -0
- package/dist/router.js +115 -98
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +124 -103
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
- package/router.ts +118 -78
- package/utils.ts +18 -30
package/dist/router.d.ts
CHANGED
|
@@ -257,6 +257,7 @@ export interface FutureConfig {
|
|
|
257
257
|
v7_normalizeFormMethod: boolean;
|
|
258
258
|
v7_partialHydration: boolean;
|
|
259
259
|
v7_prependBasename: boolean;
|
|
260
|
+
v7_relativeSplatPath: boolean;
|
|
260
261
|
}
|
|
261
262
|
/**
|
|
262
263
|
* Initialization options for createRouter
|
|
@@ -481,6 +482,12 @@ export declare const IDLE_BLOCKER: BlockerUnblocked;
|
|
|
481
482
|
*/
|
|
482
483
|
export declare function createRouter(init: RouterInit): Router;
|
|
483
484
|
export declare const UNSAFE_DEFERRED_SYMBOL: unique symbol;
|
|
485
|
+
/**
|
|
486
|
+
* Future flags to toggle new feature behavior
|
|
487
|
+
*/
|
|
488
|
+
export interface StaticHandlerFutureConfig {
|
|
489
|
+
v7_relativeSplatPath: boolean;
|
|
490
|
+
}
|
|
484
491
|
export interface CreateStaticHandlerOptions {
|
|
485
492
|
basename?: string;
|
|
486
493
|
/**
|
|
@@ -488,6 +495,7 @@ export interface CreateStaticHandlerOptions {
|
|
|
488
495
|
*/
|
|
489
496
|
detectErrorBoundary?: DetectErrorBoundaryFunction;
|
|
490
497
|
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
498
|
+
future?: Partial<StaticHandlerFutureConfig>;
|
|
491
499
|
}
|
|
492
500
|
export declare function createStaticHandler(routes: AgnosticRouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
|
|
493
501
|
/**
|
package/dist/router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v0.0.0-experimental-
|
|
2
|
+
* @remix-run/router v0.0.0-experimental-8bb3ffdf
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -940,9 +940,15 @@ function getPathContributingMatches(matches) {
|
|
|
940
940
|
}
|
|
941
941
|
// Return the array of pathnames for the current route matches - used to
|
|
942
942
|
// generate the routePathnames input for resolveTo()
|
|
943
|
-
function getResolveToMatches(matches) {
|
|
944
|
-
|
|
945
|
-
|
|
943
|
+
function getResolveToMatches(matches, v7_relativeSplatPath) {
|
|
944
|
+
let pathMatches = getPathContributingMatches(matches);
|
|
945
|
+
// When v7_relativeSplatPath is enabled, use the full pathname for the leaf
|
|
946
|
+
// match so we include splat values for "." links. See:
|
|
947
|
+
// https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329
|
|
948
|
+
if (v7_relativeSplatPath) {
|
|
949
|
+
return pathMatches.map((match, idx) => idx === matches.length - 1 ? match.pathname : match.pathnameBase);
|
|
950
|
+
}
|
|
951
|
+
return pathMatches.map(match => match.pathnameBase);
|
|
946
952
|
}
|
|
947
953
|
/**
|
|
948
954
|
* @private
|
|
@@ -974,34 +980,20 @@ function resolveTo(toArg, routePathnames, locationPathname, isPathRelative) {
|
|
|
974
980
|
// to the current location's pathname and *not* the route pathname.
|
|
975
981
|
if (toPathname == null) {
|
|
976
982
|
from = locationPathname;
|
|
977
|
-
} else if (isPathRelative) {
|
|
978
|
-
let fromSegments = routePathnames[routePathnames.length - 1].replace(/^\//, "").split("/");
|
|
979
|
-
if (toPathname.startsWith("..")) {
|
|
980
|
-
let toSegments = toPathname.split("/");
|
|
981
|
-
// With relative="path", each leading .. segment means "go up one URL segment"
|
|
982
|
-
while (toSegments[0] === "..") {
|
|
983
|
-
toSegments.shift();
|
|
984
|
-
fromSegments.pop();
|
|
985
|
-
}
|
|
986
|
-
to.pathname = toSegments.join("/");
|
|
987
|
-
}
|
|
988
|
-
from = "/" + fromSegments.join("/");
|
|
989
983
|
} else {
|
|
990
984
|
let routePathnameIndex = routePathnames.length - 1;
|
|
991
|
-
|
|
985
|
+
// With relative="route" (the default), each leading .. segment means
|
|
986
|
+
// "go up one route" instead of "go up one URL segment". This is a key
|
|
987
|
+
// difference from how <a href> works and a major reason we call this a
|
|
988
|
+
// "to" value instead of a "href".
|
|
989
|
+
if (!isPathRelative && toPathname.startsWith("..")) {
|
|
992
990
|
let toSegments = toPathname.split("/");
|
|
993
|
-
// With relative="route" (the default), each leading .. segment means
|
|
994
|
-
// "go up one route" instead of "go up one URL segment". This is a key
|
|
995
|
-
// difference from how <a href> works and a major reason we call this a
|
|
996
|
-
// "to" value instead of a "href".
|
|
997
991
|
while (toSegments[0] === "..") {
|
|
998
992
|
toSegments.shift();
|
|
999
993
|
routePathnameIndex -= 1;
|
|
1000
994
|
}
|
|
1001
995
|
to.pathname = toSegments.join("/");
|
|
1002
996
|
}
|
|
1003
|
-
// If there are more ".." segments than parent routes, resolve relative to
|
|
1004
|
-
// the root / URL.
|
|
1005
997
|
from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
|
|
1006
998
|
}
|
|
1007
999
|
let path = resolvePath(to, from);
|
|
@@ -1337,7 +1329,8 @@ function createRouter(init) {
|
|
|
1337
1329
|
v7_fetcherPersist: false,
|
|
1338
1330
|
v7_normalizeFormMethod: false,
|
|
1339
1331
|
v7_partialHydration: false,
|
|
1340
|
-
v7_prependBasename: false
|
|
1332
|
+
v7_prependBasename: false,
|
|
1333
|
+
v7_relativeSplatPath: false
|
|
1341
1334
|
}, init.future);
|
|
1342
1335
|
// Cleanup function for history
|
|
1343
1336
|
let unlistenHistory = null;
|
|
@@ -1373,17 +1366,28 @@ function createRouter(init) {
|
|
|
1373
1366
|
[route.id]: error
|
|
1374
1367
|
};
|
|
1375
1368
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1369
|
+
let initialized;
|
|
1370
|
+
let hasLazyRoutes = initialMatches.some(m => m.route.lazy);
|
|
1371
|
+
let hasLoaders = initialMatches.some(m => m.route.loader);
|
|
1372
|
+
if (hasLazyRoutes) {
|
|
1373
|
+
// All initialMatches need to be loaded before we're ready. If we have lazy
|
|
1374
|
+
// functions around still then we'll need to run them in initialize()
|
|
1375
|
+
initialized = false;
|
|
1376
|
+
} else if (!hasLoaders) {
|
|
1377
|
+
// If we've got no loaders to run, then we're good to go
|
|
1378
|
+
initialized = true;
|
|
1379
|
+
} else if (future.v7_partialHydration) {
|
|
1380
|
+
// If partial hydration is enabled, we're initialized so long as we were
|
|
1381
|
+
// provided with hydrationData for every route with a loader, and no loaders
|
|
1382
|
+
// were marked for explicit hydration
|
|
1383
|
+
let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
|
|
1384
|
+
let errors = init.hydrationData ? init.hydrationData.errors : null;
|
|
1385
|
+
initialized = initialMatches.every(m => m.route.loader && m.route.loader.hydrate !== true && (loaderData && loaderData[m.route.id] !== undefined || errors && errors[m.route.id] !== undefined));
|
|
1386
|
+
} else {
|
|
1387
|
+
// Without partial hydration - we're initialized if we were provided any
|
|
1388
|
+
// hydrationData - which is expected to be complete
|
|
1389
|
+
initialized = init.hydrationData != null;
|
|
1390
|
+
}
|
|
1387
1391
|
let router;
|
|
1388
1392
|
let state = {
|
|
1389
1393
|
historyAction: init.history.action,
|
|
@@ -1526,7 +1530,7 @@ function createRouter(init) {
|
|
|
1526
1530
|
// in the normal navigation flow. For SSR it's expected that lazy modules are
|
|
1527
1531
|
// resolved prior to router creation since we can't go into a fallbackElement
|
|
1528
1532
|
// UI for SSR'd apps
|
|
1529
|
-
if (!state.initialized
|
|
1533
|
+
if (!state.initialized) {
|
|
1530
1534
|
startNavigation(Action.Pop, state.location, {
|
|
1531
1535
|
initialHydration: true
|
|
1532
1536
|
});
|
|
@@ -1704,7 +1708,7 @@ function createRouter(init) {
|
|
|
1704
1708
|
init.history.go(to);
|
|
1705
1709
|
return;
|
|
1706
1710
|
}
|
|
1707
|
-
let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, to, opts == null ? void 0 : opts.fromRouteId, opts == null ? void 0 : opts.relative);
|
|
1711
|
+
let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, to, future.v7_relativeSplatPath, opts == null ? void 0 : opts.fromRouteId, opts == null ? void 0 : opts.relative);
|
|
1708
1712
|
let {
|
|
1709
1713
|
path,
|
|
1710
1714
|
submission,
|
|
@@ -1937,7 +1941,7 @@ function createRouter(init) {
|
|
|
1937
1941
|
})
|
|
1938
1942
|
};
|
|
1939
1943
|
} else {
|
|
1940
|
-
result = await callLoaderOrAction("action", request, actionMatch, matches, manifest, mapRouteProperties, basename);
|
|
1944
|
+
result = await callLoaderOrAction("action", request, actionMatch, matches, manifest, mapRouteProperties, basename, future.v7_relativeSplatPath);
|
|
1941
1945
|
if (request.signal.aborted) {
|
|
1942
1946
|
return {
|
|
1943
1947
|
shortCircuited: true
|
|
@@ -2135,7 +2139,7 @@ function createRouter(init) {
|
|
|
2135
2139
|
if (fetchControllers.has(key)) abortFetcher(key);
|
|
2136
2140
|
let flushSync = (opts && opts.unstable_flushSync) === true;
|
|
2137
2141
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
2138
|
-
let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, href, routeId, opts == null ? void 0 : opts.relative);
|
|
2142
|
+
let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, href, future.v7_relativeSplatPath, routeId, opts == null ? void 0 : opts.relative);
|
|
2139
2143
|
let matches = matchRoutes(routesToUse, normalizedPath, basename);
|
|
2140
2144
|
if (!matches) {
|
|
2141
2145
|
setFetcherError(key, routeId, getInternalRouterError(404, {
|
|
@@ -2196,7 +2200,7 @@ function createRouter(init) {
|
|
|
2196
2200
|
let fetchRequest = createClientSideRequest(init.history, path, abortController.signal, submission);
|
|
2197
2201
|
fetchControllers.set(key, abortController);
|
|
2198
2202
|
let originatingLoadId = incrementingLoadId;
|
|
2199
|
-
let actionResult = await callLoaderOrAction("action", fetchRequest, match, requestMatches, manifest, mapRouteProperties, basename);
|
|
2203
|
+
let actionResult = await callLoaderOrAction("action", fetchRequest, match, requestMatches, manifest, mapRouteProperties, basename, future.v7_relativeSplatPath);
|
|
2200
2204
|
if (fetchRequest.signal.aborted) {
|
|
2201
2205
|
// We can delete this so long as we weren't aborted by our own fetcher
|
|
2202
2206
|
// re-submit which would have put _new_ controller is in fetchControllers
|
|
@@ -2205,31 +2209,38 @@ function createRouter(init) {
|
|
|
2205
2209
|
}
|
|
2206
2210
|
return;
|
|
2207
2211
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
fetchControllers.delete(key);
|
|
2214
|
-
if (pendingNavigationLoadId > originatingLoadId) {
|
|
2215
|
-
// A new navigation was kicked off after our action started, so that
|
|
2216
|
-
// should take precedence over this redirect navigation. We already
|
|
2217
|
-
// set isRevalidationRequired so all loaders for the new route should
|
|
2218
|
-
// fire unless opted out via shouldRevalidate
|
|
2212
|
+
// When using v7_fetcherPersist, we don't want errors bubbling up to the UI
|
|
2213
|
+
// or redirects processed for unmounted fetchers so we just revert them to
|
|
2214
|
+
// idle
|
|
2215
|
+
if (future.v7_fetcherPersist && deletedFetchers.has(key)) {
|
|
2216
|
+
if (isRedirectResult(actionResult) || isErrorResult(actionResult)) {
|
|
2219
2217
|
updateFetcherState(key, getDoneFetcher(undefined));
|
|
2220
2218
|
return;
|
|
2221
|
-
} else {
|
|
2222
|
-
fetchRedirectIds.add(key);
|
|
2223
|
-
updateFetcherState(key, getLoadingFetcher(submission));
|
|
2224
|
-
return startRedirectNavigation(state, actionResult, {
|
|
2225
|
-
fetcherSubmission: submission
|
|
2226
|
-
});
|
|
2227
2219
|
}
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2220
|
+
// Let SuccessResult's fall through for revalidation
|
|
2221
|
+
} else {
|
|
2222
|
+
if (isRedirectResult(actionResult)) {
|
|
2223
|
+
fetchControllers.delete(key);
|
|
2224
|
+
if (pendingNavigationLoadId > originatingLoadId) {
|
|
2225
|
+
// A new navigation was kicked off after our action started, so that
|
|
2226
|
+
// should take precedence over this redirect navigation. We already
|
|
2227
|
+
// set isRevalidationRequired so all loaders for the new route should
|
|
2228
|
+
// fire unless opted out via shouldRevalidate
|
|
2229
|
+
updateFetcherState(key, getDoneFetcher(undefined));
|
|
2230
|
+
return;
|
|
2231
|
+
} else {
|
|
2232
|
+
fetchRedirectIds.add(key);
|
|
2233
|
+
updateFetcherState(key, getLoadingFetcher(submission));
|
|
2234
|
+
return startRedirectNavigation(state, actionResult, {
|
|
2235
|
+
fetcherSubmission: submission
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
// Process any non-redirect errors thrown
|
|
2240
|
+
if (isErrorResult(actionResult)) {
|
|
2241
|
+
setFetcherError(key, routeId, actionResult.error);
|
|
2242
|
+
return;
|
|
2243
|
+
}
|
|
2233
2244
|
}
|
|
2234
2245
|
if (isDeferredResult(actionResult)) {
|
|
2235
2246
|
throw getInternalRouterError(400, {
|
|
@@ -2341,7 +2352,7 @@ function createRouter(init) {
|
|
|
2341
2352
|
let fetchRequest = createClientSideRequest(init.history, path, abortController.signal);
|
|
2342
2353
|
fetchControllers.set(key, abortController);
|
|
2343
2354
|
let originatingLoadId = incrementingLoadId;
|
|
2344
|
-
let result = await callLoaderOrAction("loader", fetchRequest, match, matches, manifest, mapRouteProperties, basename);
|
|
2355
|
+
let result = await callLoaderOrAction("loader", fetchRequest, match, matches, manifest, mapRouteProperties, basename, future.v7_relativeSplatPath);
|
|
2345
2356
|
// Deferred isn't supported for fetcher loads, await everything and treat it
|
|
2346
2357
|
// as a normal load. resolveDeferredData will return undefined if this
|
|
2347
2358
|
// fetcher gets aborted, so we just leave result untouched and short circuit
|
|
@@ -2357,6 +2368,8 @@ function createRouter(init) {
|
|
|
2357
2368
|
if (fetchRequest.signal.aborted) {
|
|
2358
2369
|
return;
|
|
2359
2370
|
}
|
|
2371
|
+
// We don't want errors bubbling up or redirects followed for unmounted
|
|
2372
|
+
// fetchers, so short circuit here if it was removed from the UI
|
|
2360
2373
|
if (deletedFetchers.has(key)) {
|
|
2361
2374
|
updateFetcherState(key, getDoneFetcher(undefined));
|
|
2362
2375
|
return;
|
|
@@ -2480,9 +2493,9 @@ function createRouter(init) {
|
|
|
2480
2493
|
// Call all navigation loaders and revalidating fetcher loaders in parallel,
|
|
2481
2494
|
// then slice off the results into separate arrays so we can handle them
|
|
2482
2495
|
// accordingly
|
|
2483
|
-
let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, manifest, mapRouteProperties, basename)), ...fetchersToLoad.map(f => {
|
|
2496
|
+
let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, manifest, mapRouteProperties, basename, future.v7_relativeSplatPath)), ...fetchersToLoad.map(f => {
|
|
2484
2497
|
if (f.matches && f.match && f.controller) {
|
|
2485
|
-
return callLoaderOrAction("loader", createClientSideRequest(init.history, f.path, f.controller.signal), f.match, f.matches, manifest, mapRouteProperties, basename);
|
|
2498
|
+
return callLoaderOrAction("loader", createClientSideRequest(init.history, f.path, f.controller.signal), f.match, f.matches, manifest, mapRouteProperties, basename, future.v7_relativeSplatPath);
|
|
2486
2499
|
} else {
|
|
2487
2500
|
let error = {
|
|
2488
2501
|
type: ResultType.error,
|
|
@@ -2807,6 +2820,10 @@ function createStaticHandler(routes, opts) {
|
|
|
2807
2820
|
} else {
|
|
2808
2821
|
mapRouteProperties = defaultMapRouteProperties;
|
|
2809
2822
|
}
|
|
2823
|
+
// Config driven behavior flags
|
|
2824
|
+
let future = _extends({
|
|
2825
|
+
v7_relativeSplatPath: false
|
|
2826
|
+
}, opts ? opts.future : null);
|
|
2810
2827
|
let dataRoutes = convertRoutesToDataRoutes(routes, mapRouteProperties, undefined, manifest);
|
|
2811
2828
|
/**
|
|
2812
2829
|
* The query() method is intended for document requests, in which we want to
|
|
@@ -3016,7 +3033,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3016
3033
|
error
|
|
3017
3034
|
};
|
|
3018
3035
|
} else {
|
|
3019
|
-
result = await callLoaderOrAction("action", request, actionMatch, matches, manifest, mapRouteProperties, basename, {
|
|
3036
|
+
result = await callLoaderOrAction("action", request, actionMatch, matches, manifest, mapRouteProperties, basename, future.v7_relativeSplatPath, {
|
|
3020
3037
|
isStaticRequest: true,
|
|
3021
3038
|
isRouteRequest,
|
|
3022
3039
|
requestContext
|
|
@@ -3131,7 +3148,7 @@ function createStaticHandler(routes, opts) {
|
|
|
3131
3148
|
activeDeferreds: null
|
|
3132
3149
|
};
|
|
3133
3150
|
}
|
|
3134
|
-
let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, manifest, mapRouteProperties, basename, {
|
|
3151
|
+
let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, manifest, mapRouteProperties, basename, future.v7_relativeSplatPath, {
|
|
3135
3152
|
isStaticRequest: true,
|
|
3136
3153
|
isRouteRequest,
|
|
3137
3154
|
requestContext
|
|
@@ -3181,7 +3198,7 @@ function getStaticContextFromError(routes, context, error) {
|
|
|
3181
3198
|
function isSubmissionNavigation(opts) {
|
|
3182
3199
|
return opts != null && ("formData" in opts && opts.formData != null || "body" in opts && opts.body !== undefined);
|
|
3183
3200
|
}
|
|
3184
|
-
function normalizeTo(location, matches, basename, prependBasename, to, fromRouteId, relative) {
|
|
3201
|
+
function normalizeTo(location, matches, basename, prependBasename, to, v7_relativeSplatPath, fromRouteId, relative) {
|
|
3185
3202
|
let contextualMatches;
|
|
3186
3203
|
let activeRouteMatch;
|
|
3187
3204
|
if (fromRouteId) {
|
|
@@ -3200,7 +3217,7 @@ function normalizeTo(location, matches, basename, prependBasename, to, fromRoute
|
|
|
3200
3217
|
activeRouteMatch = matches[matches.length - 1];
|
|
3201
3218
|
}
|
|
3202
3219
|
// Resolve the relative path
|
|
3203
|
-
let path = resolveTo(to ? to : ".", getResolveToMatches(contextualMatches), stripBasename(location.pathname, basename) || location.pathname, relative === "path");
|
|
3220
|
+
let path = resolveTo(to ? to : ".", getResolveToMatches(contextualMatches, v7_relativeSplatPath), stripBasename(location.pathname, basename) || location.pathname, relative === "path");
|
|
3204
3221
|
// When `to` is not specified we inherit search/hash from the current
|
|
3205
3222
|
// location, unlike when to="." and we just inherit the path.
|
|
3206
3223
|
// See https://github.com/remix-run/remix/issues/927
|
|
@@ -3365,18 +3382,24 @@ function getMatchesToLoad(history, state, matches, submission, location, isIniti
|
|
|
3365
3382
|
let boundaryId = pendingError ? Object.keys(pendingError)[0] : undefined;
|
|
3366
3383
|
let boundaryMatches = getLoaderMatchesUntilBoundary(matches, boundaryId);
|
|
3367
3384
|
let navigationMatches = boundaryMatches.filter((match, index) => {
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
}
|
|
3373
|
-
if (match.route.lazy) {
|
|
3385
|
+
let {
|
|
3386
|
+
route
|
|
3387
|
+
} = match;
|
|
3388
|
+
if (route.lazy) {
|
|
3374
3389
|
// We haven't loaded this route yet so we don't know if it's got a loader!
|
|
3375
3390
|
return true;
|
|
3376
3391
|
}
|
|
3377
|
-
if (
|
|
3392
|
+
if (route.loader == null) {
|
|
3378
3393
|
return false;
|
|
3379
3394
|
}
|
|
3395
|
+
if (isInitialLoad) {
|
|
3396
|
+
if (route.loader.hydrate) {
|
|
3397
|
+
return true;
|
|
3398
|
+
}
|
|
3399
|
+
return state.loaderData[route.id] === undefined && (
|
|
3400
|
+
// Don't re-run if the loader ran and threw an error
|
|
3401
|
+
!state.errors || state.errors[route.id] === undefined);
|
|
3402
|
+
}
|
|
3380
3403
|
// Always call the loader on new route instances and pending defer cancellations
|
|
3381
3404
|
if (isNewLoader(state.loaderData, state.matches[index], match) || cancelledDeferredRoutes.some(id => id === match.route.id)) {
|
|
3382
3405
|
return true;
|
|
@@ -3473,19 +3496,6 @@ function getMatchesToLoad(history, state, matches, submission, location, isIniti
|
|
|
3473
3496
|
});
|
|
3474
3497
|
return [navigationMatches, revalidatingFetchers];
|
|
3475
3498
|
}
|
|
3476
|
-
// Is this route unhydrated (when v7_partialHydration=true) such that we need
|
|
3477
|
-
// to call it's loader on the initial router creation
|
|
3478
|
-
function isUnhydratedRoute(state, route) {
|
|
3479
|
-
if (!route.loader) {
|
|
3480
|
-
return false;
|
|
3481
|
-
}
|
|
3482
|
-
if (route.loader.hydrate) {
|
|
3483
|
-
return true;
|
|
3484
|
-
}
|
|
3485
|
-
return state.loaderData[route.id] === undefined && (!state.errors ||
|
|
3486
|
-
// Loader ran but errored - don't re-run
|
|
3487
|
-
state.errors[route.id] === undefined);
|
|
3488
|
-
}
|
|
3489
3499
|
function isNewLoader(currentLoaderData, currentMatch, match) {
|
|
3490
3500
|
let isNew =
|
|
3491
3501
|
// [a] -> [a, b]
|
|
@@ -3565,7 +3575,7 @@ async function loadLazyRouteModule(route, mapRouteProperties, manifest) {
|
|
|
3565
3575
|
lazy: undefined
|
|
3566
3576
|
}));
|
|
3567
3577
|
}
|
|
3568
|
-
async function callLoaderOrAction(type, request, match, matches, manifest, mapRouteProperties, basename, opts) {
|
|
3578
|
+
async function callLoaderOrAction(type, request, match, matches, manifest, mapRouteProperties, basename, v7_relativeSplatPath, opts) {
|
|
3569
3579
|
if (opts === void 0) {
|
|
3570
3580
|
opts = {};
|
|
3571
3581
|
}
|
|
@@ -3653,7 +3663,7 @@ async function callLoaderOrAction(type, request, match, matches, manifest, mapRo
|
|
|
3653
3663
|
invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
|
|
3654
3664
|
// Support relative routing in internal redirects
|
|
3655
3665
|
if (!ABSOLUTE_URL_REGEX.test(location)) {
|
|
3656
|
-
location = normalizeTo(new URL(request.url), matches.slice(0, matches.indexOf(match) + 1), basename, true, location);
|
|
3666
|
+
location = normalizeTo(new URL(request.url), matches.slice(0, matches.indexOf(match) + 1), basename, true, location, v7_relativeSplatPath);
|
|
3657
3667
|
} else if (!opts.isStaticRequest) {
|
|
3658
3668
|
// Strip off the protocol+origin for same-origin + same-basename absolute
|
|
3659
3669
|
// redirects. If this is a static request, we can let it go back to the
|
|
@@ -3692,13 +3702,20 @@ async function callLoaderOrAction(type, request, match, matches, manifest, mapRo
|
|
|
3692
3702
|
throw queryRouteResponse;
|
|
3693
3703
|
}
|
|
3694
3704
|
let data;
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3705
|
+
try {
|
|
3706
|
+
let contentType = result.headers.get("Content-Type");
|
|
3707
|
+
// Check between word boundaries instead of startsWith() due to the last
|
|
3708
|
+
// paragraph of https://httpwg.org/specs/rfc9110.html#field.content-type
|
|
3709
|
+
if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
|
3710
|
+
data = await result.json();
|
|
3711
|
+
} else {
|
|
3712
|
+
data = await result.text();
|
|
3713
|
+
}
|
|
3714
|
+
} catch (e) {
|
|
3715
|
+
return {
|
|
3716
|
+
type: ResultType.error,
|
|
3717
|
+
error: e
|
|
3718
|
+
};
|
|
3702
3719
|
}
|
|
3703
3720
|
if (resultType === ResultType.error) {
|
|
3704
3721
|
return {
|