@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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.17.0
2
+ * @remix-run/router v1.17.1
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1218,7 +1218,7 @@
1218
1218
  // match so we include splat values for "." links. See:
1219
1219
  // https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329
1220
1220
  if (v7_relativeSplatPath) {
1221
- return pathMatches.map((match, idx) => idx === matches.length - 1 ? match.pathname : match.pathnameBase);
1221
+ return pathMatches.map((match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase);
1222
1222
  }
1223
1223
  return pathMatches.map(match => match.pathnameBase);
1224
1224
  }
@@ -1731,6 +1731,16 @@
1731
1731
  [route.id]: error
1732
1732
  };
1733
1733
  }
1734
+
1735
+ // If the user provided a patchRoutesOnMiss implementation and our initial
1736
+ // match is a splat route, clear them out so we run through lazy discovery
1737
+ // on hydration in case there's a more accurate lazy route match
1738
+ if (initialMatches && patchRoutesOnMissImpl) {
1739
+ let fogOfWar = checkFogOfWar(initialMatches, dataRoutes, init.history.location.pathname);
1740
+ if (fogOfWar.active) {
1741
+ initialMatches = null;
1742
+ }
1743
+ }
1734
1744
  let initialized;
1735
1745
  if (!initialMatches) {
1736
1746
  // We need to run patchRoutesOnMiss in initialize()
@@ -2060,6 +2070,8 @@
2060
2070
  // Always respect the user flag. Otherwise don't reset on mutation
2061
2071
  // submission navigations unless they redirect
2062
2072
  let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && ((_location$state2 = location.state) == null ? void 0 : _location$state2._isRedirect) !== true;
2073
+
2074
+ // Commit any in-flight routes at the end of the HMR revalidation "navigation"
2063
2075
  if (inFlightDataRoutes) {
2064
2076
  dataRoutes = inFlightDataRoutes;
2065
2077
  inFlightDataRoutes = undefined;
@@ -3505,7 +3517,7 @@
3505
3517
  };
3506
3518
  } else {
3507
3519
  let leafRoute = matches[matches.length - 1].route;
3508
- if (leafRoute.path === "*") {
3520
+ if (leafRoute.path && (leafRoute.path === "*" || leafRoute.path.endsWith("/*"))) {
3509
3521
  // If we matched a splat, it might only be because we haven't yet fetched
3510
3522
  // the children that would match with a higher score, so let's fetch
3511
3523
  // around and find out
@@ -3526,21 +3538,32 @@
3526
3538
  let partialMatches = matches;
3527
3539
  let route = partialMatches.length > 0 ? partialMatches[partialMatches.length - 1].route : null;
3528
3540
  while (true) {
3541
+ let isNonHMR = inFlightDataRoutes == null;
3542
+ let routesToUse = inFlightDataRoutes || dataRoutes;
3529
3543
  try {
3530
- await loadLazyRouteChildren(patchRoutesOnMissImpl, pathname, partialMatches, dataRoutes || inFlightDataRoutes, manifest, mapRouteProperties, pendingPatchRoutes, signal);
3544
+ await loadLazyRouteChildren(patchRoutesOnMissImpl, pathname, partialMatches, routesToUse, manifest, mapRouteProperties, pendingPatchRoutes, signal);
3531
3545
  } catch (e) {
3532
3546
  return {
3533
3547
  type: "error",
3534
3548
  error: e,
3535
3549
  partialMatches
3536
3550
  };
3551
+ } finally {
3552
+ // If we are not in the middle of an HMR revalidation and we changed the
3553
+ // routes, provide a new identity so when we `updateState` at the end of
3554
+ // this navigation/fetch `router.routes` will be a new identity and
3555
+ // trigger a re-run of memoized `router.routes` dependencies.
3556
+ // HMR will already update the identity and reflow when it lands
3557
+ // `inFlightDataRoutes` in `completeNavigation`
3558
+ if (isNonHMR) {
3559
+ dataRoutes = [...dataRoutes];
3560
+ }
3537
3561
  }
3538
3562
  if (signal.aborted) {
3539
3563
  return {
3540
3564
  type: "aborted"
3541
3565
  };
3542
3566
  }
3543
- let routesToUse = inFlightDataRoutes || dataRoutes;
3544
3567
  let newMatches = matchRoutes(routesToUse, pathname, basename);
3545
3568
  let matchedSplat = false;
3546
3569
  if (newMatches) {
@@ -3593,6 +3616,21 @@
3593
3616
  manifest = {};
3594
3617
  inFlightDataRoutes = convertRoutesToDataRoutes(newRoutes, mapRouteProperties, undefined, manifest);
3595
3618
  }
3619
+ function patchRoutes(routeId, children) {
3620
+ let isNonHMR = inFlightDataRoutes == null;
3621
+ let routesToUse = inFlightDataRoutes || dataRoutes;
3622
+ patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties);
3623
+
3624
+ // If we are not in the middle of an HMR revalidation and we changed the
3625
+ // routes, provide a new identity and trigger a reflow via `updateState`
3626
+ // to re-run memoized `router.routes` dependencies.
3627
+ // HMR will already update the identity and reflow when it lands
3628
+ // `inFlightDataRoutes` in `completeNavigation`
3629
+ if (isNonHMR) {
3630
+ dataRoutes = [...dataRoutes];
3631
+ updateState({});
3632
+ }
3633
+ }
3596
3634
  router = {
3597
3635
  get basename() {
3598
3636
  return basename;
@@ -3624,9 +3662,7 @@
3624
3662
  dispose,
3625
3663
  getBlocker,
3626
3664
  deleteBlocker,
3627
- patchRoutes(routeId, children) {
3628
- return patchRoutes(routeId, children, dataRoutes || inFlightDataRoutes, manifest, mapRouteProperties);
3629
- },
3665
+ patchRoutes,
3630
3666
  _internalFetchControllers: fetchControllers,
3631
3667
  _internalActiveDeferreds: activeDeferreds,
3632
3668
  // TODO: Remove setRoutes, it's temporary to avoid dealing with
@@ -4444,7 +4480,7 @@
4444
4480
  }
4445
4481
 
4446
4482
  /**
4447
- * Idempotent utility to execute route.children() method to lazily load route
4483
+ * Idempotent utility to execute patchRoutesOnMiss() to lazily load route
4448
4484
  * definitions and update the routes/routeManifest
4449
4485
  */
4450
4486
  async function loadLazyRouteChildren(patchRoutesOnMissImpl, path, matches, routes, manifest, mapRouteProperties, pendingRouteChildren, signal) {
@@ -4457,7 +4493,7 @@
4457
4493
  matches,
4458
4494
  patch: (routeId, children) => {
4459
4495
  if (!signal.aborted) {
4460
- patchRoutes(routeId, children, routes, manifest, mapRouteProperties);
4496
+ patchRoutesImpl(routeId, children, routes, manifest, mapRouteProperties);
4461
4497
  }
4462
4498
  }
4463
4499
  });
@@ -4470,7 +4506,7 @@
4470
4506
  pendingRouteChildren.delete(key);
4471
4507
  }
4472
4508
  }
4473
- function patchRoutes(routeId, children, routes, manifest, mapRouteProperties) {
4509
+ function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties) {
4474
4510
  if (routeId) {
4475
4511
  var _route$children;
4476
4512
  let route = manifest[routeId];
@@ -4482,8 +4518,8 @@
4482
4518
  route.children = dataChildren;
4483
4519
  }
4484
4520
  } else {
4485
- let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, ["patch", String(routes.length || "0")], manifest);
4486
- routes.push(...dataChildren);
4521
+ let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, ["patch", String(routesToUse.length || "0")], manifest);
4522
+ routesToUse.push(...dataChildren);
4487
4523
  }
4488
4524
  }
4489
4525