@remix-run/router 1.17.0 → 1.17.1
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 +7 -0
- package/dist/router.cjs.js +49 -13
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +2 -1
- package/dist/router.js +46 -13
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +49 -13
- 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/package.json +1 -1
- package/router.ts +66 -19
- package/utils.ts +1 -1
package/dist/router.d.ts
CHANGED
|
@@ -165,7 +165,8 @@ export interface Router {
|
|
|
165
165
|
* PRIVATE DO NOT USE
|
|
166
166
|
*
|
|
167
167
|
* Patch additional children routes into an existing parent route
|
|
168
|
-
* @param routeId The parent route id
|
|
168
|
+
* @param routeId The parent route id or a callback function accepting `patch`
|
|
169
|
+
* to perform batch patching
|
|
169
170
|
* @param children The additional children routes
|
|
170
171
|
*/
|
|
171
172
|
patchRoutes(routeId: string | null, children: AgnosticRouteObject[]): void;
|
package/dist/router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.17.
|
|
2
|
+
* @remix-run/router v1.17.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -957,7 +957,7 @@ function getResolveToMatches(matches, v7_relativeSplatPath) {
|
|
|
957
957
|
// match so we include splat values for "." links. See:
|
|
958
958
|
// https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329
|
|
959
959
|
if (v7_relativeSplatPath) {
|
|
960
|
-
return pathMatches.map((match, idx) => idx ===
|
|
960
|
+
return pathMatches.map((match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase);
|
|
961
961
|
}
|
|
962
962
|
return pathMatches.map(match => match.pathnameBase);
|
|
963
963
|
}
|
|
@@ -1380,6 +1380,15 @@ function createRouter(init) {
|
|
|
1380
1380
|
[route.id]: error
|
|
1381
1381
|
};
|
|
1382
1382
|
}
|
|
1383
|
+
// If the user provided a patchRoutesOnMiss implementation and our initial
|
|
1384
|
+
// match is a splat route, clear them out so we run through lazy discovery
|
|
1385
|
+
// on hydration in case there's a more accurate lazy route match
|
|
1386
|
+
if (initialMatches && patchRoutesOnMissImpl) {
|
|
1387
|
+
let fogOfWar = checkFogOfWar(initialMatches, dataRoutes, init.history.location.pathname);
|
|
1388
|
+
if (fogOfWar.active) {
|
|
1389
|
+
initialMatches = null;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1383
1392
|
let initialized;
|
|
1384
1393
|
if (!initialMatches) {
|
|
1385
1394
|
// We need to run patchRoutesOnMiss in initialize()
|
|
@@ -1673,6 +1682,7 @@ function createRouter(init) {
|
|
|
1673
1682
|
// Always respect the user flag. Otherwise don't reset on mutation
|
|
1674
1683
|
// submission navigations unless they redirect
|
|
1675
1684
|
let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && ((_location$state2 = location.state) == null ? void 0 : _location$state2._isRedirect) !== true;
|
|
1685
|
+
// Commit any in-flight routes at the end of the HMR revalidation "navigation"
|
|
1676
1686
|
if (inFlightDataRoutes) {
|
|
1677
1687
|
dataRoutes = inFlightDataRoutes;
|
|
1678
1688
|
inFlightDataRoutes = undefined;
|
|
@@ -3050,7 +3060,7 @@ function createRouter(init) {
|
|
|
3050
3060
|
};
|
|
3051
3061
|
} else {
|
|
3052
3062
|
let leafRoute = matches[matches.length - 1].route;
|
|
3053
|
-
if (leafRoute.path === "*") {
|
|
3063
|
+
if (leafRoute.path && (leafRoute.path === "*" || leafRoute.path.endsWith("/*"))) {
|
|
3054
3064
|
// If we matched a splat, it might only be because we haven't yet fetched
|
|
3055
3065
|
// the children that would match with a higher score, so let's fetch
|
|
3056
3066
|
// around and find out
|
|
@@ -3071,21 +3081,32 @@ function createRouter(init) {
|
|
|
3071
3081
|
let partialMatches = matches;
|
|
3072
3082
|
let route = partialMatches.length > 0 ? partialMatches[partialMatches.length - 1].route : null;
|
|
3073
3083
|
while (true) {
|
|
3084
|
+
let isNonHMR = inFlightDataRoutes == null;
|
|
3085
|
+
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
3074
3086
|
try {
|
|
3075
|
-
await loadLazyRouteChildren(patchRoutesOnMissImpl, pathname, partialMatches,
|
|
3087
|
+
await loadLazyRouteChildren(patchRoutesOnMissImpl, pathname, partialMatches, routesToUse, manifest, mapRouteProperties, pendingPatchRoutes, signal);
|
|
3076
3088
|
} catch (e) {
|
|
3077
3089
|
return {
|
|
3078
3090
|
type: "error",
|
|
3079
3091
|
error: e,
|
|
3080
3092
|
partialMatches
|
|
3081
3093
|
};
|
|
3094
|
+
} finally {
|
|
3095
|
+
// If we are not in the middle of an HMR revalidation and we changed the
|
|
3096
|
+
// routes, provide a new identity so when we `updateState` at the end of
|
|
3097
|
+
// this navigation/fetch `router.routes` will be a new identity and
|
|
3098
|
+
// trigger a re-run of memoized `router.routes` dependencies.
|
|
3099
|
+
// HMR will already update the identity and reflow when it lands
|
|
3100
|
+
// `inFlightDataRoutes` in `completeNavigation`
|
|
3101
|
+
if (isNonHMR) {
|
|
3102
|
+
dataRoutes = [...dataRoutes];
|
|
3103
|
+
}
|
|
3082
3104
|
}
|
|
3083
3105
|
if (signal.aborted) {
|
|
3084
3106
|
return {
|
|
3085
3107
|
type: "aborted"
|
|
3086
3108
|
};
|
|
3087
3109
|
}
|
|
3088
|
-
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
3089
3110
|
let newMatches = matchRoutes(routesToUse, pathname, basename);
|
|
3090
3111
|
let matchedSplat = false;
|
|
3091
3112
|
if (newMatches) {
|
|
@@ -3137,6 +3158,20 @@ function createRouter(init) {
|
|
|
3137
3158
|
manifest = {};
|
|
3138
3159
|
inFlightDataRoutes = convertRoutesToDataRoutes(newRoutes, mapRouteProperties, undefined, manifest);
|
|
3139
3160
|
}
|
|
3161
|
+
function patchRoutes(routeId, children) {
|
|
3162
|
+
let isNonHMR = inFlightDataRoutes == null;
|
|
3163
|
+
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
3164
|
+
patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties);
|
|
3165
|
+
// If we are not in the middle of an HMR revalidation and we changed the
|
|
3166
|
+
// routes, provide a new identity and trigger a reflow via `updateState`
|
|
3167
|
+
// to re-run memoized `router.routes` dependencies.
|
|
3168
|
+
// HMR will already update the identity and reflow when it lands
|
|
3169
|
+
// `inFlightDataRoutes` in `completeNavigation`
|
|
3170
|
+
if (isNonHMR) {
|
|
3171
|
+
dataRoutes = [...dataRoutes];
|
|
3172
|
+
updateState({});
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3140
3175
|
router = {
|
|
3141
3176
|
get basename() {
|
|
3142
3177
|
return basename;
|
|
@@ -3168,9 +3203,7 @@ function createRouter(init) {
|
|
|
3168
3203
|
dispose,
|
|
3169
3204
|
getBlocker,
|
|
3170
3205
|
deleteBlocker,
|
|
3171
|
-
patchRoutes
|
|
3172
|
-
return patchRoutes(routeId, children, dataRoutes || inFlightDataRoutes, manifest, mapRouteProperties);
|
|
3173
|
-
},
|
|
3206
|
+
patchRoutes,
|
|
3174
3207
|
_internalFetchControllers: fetchControllers,
|
|
3175
3208
|
_internalActiveDeferreds: activeDeferreds,
|
|
3176
3209
|
// TODO: Remove setRoutes, it's temporary to avoid dealing with
|
|
@@ -3947,7 +3980,7 @@ function shouldRevalidateLoader(loaderMatch, arg) {
|
|
|
3947
3980
|
return arg.defaultShouldRevalidate;
|
|
3948
3981
|
}
|
|
3949
3982
|
/**
|
|
3950
|
-
* Idempotent utility to execute
|
|
3983
|
+
* Idempotent utility to execute patchRoutesOnMiss() to lazily load route
|
|
3951
3984
|
* definitions and update the routes/routeManifest
|
|
3952
3985
|
*/
|
|
3953
3986
|
async function loadLazyRouteChildren(patchRoutesOnMissImpl, path, matches, routes, manifest, mapRouteProperties, pendingRouteChildren, signal) {
|
|
@@ -3960,7 +3993,7 @@ async function loadLazyRouteChildren(patchRoutesOnMissImpl, path, matches, route
|
|
|
3960
3993
|
matches,
|
|
3961
3994
|
patch: (routeId, children) => {
|
|
3962
3995
|
if (!signal.aborted) {
|
|
3963
|
-
|
|
3996
|
+
patchRoutesImpl(routeId, children, routes, manifest, mapRouteProperties);
|
|
3964
3997
|
}
|
|
3965
3998
|
}
|
|
3966
3999
|
});
|
|
@@ -3973,7 +4006,7 @@ async function loadLazyRouteChildren(patchRoutesOnMissImpl, path, matches, route
|
|
|
3973
4006
|
pendingRouteChildren.delete(key);
|
|
3974
4007
|
}
|
|
3975
4008
|
}
|
|
3976
|
-
function
|
|
4009
|
+
function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties) {
|
|
3977
4010
|
if (routeId) {
|
|
3978
4011
|
var _route$children;
|
|
3979
4012
|
let route = manifest[routeId];
|
|
@@ -3985,8 +4018,8 @@ function patchRoutes(routeId, children, routes, manifest, mapRouteProperties) {
|
|
|
3985
4018
|
route.children = dataChildren;
|
|
3986
4019
|
}
|
|
3987
4020
|
} else {
|
|
3988
|
-
let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, ["patch", String(
|
|
3989
|
-
|
|
4021
|
+
let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, ["patch", String(routesToUse.length || "0")], manifest);
|
|
4022
|
+
routesToUse.push(...dataChildren);
|
|
3990
4023
|
}
|
|
3991
4024
|
}
|
|
3992
4025
|
/**
|