@remix-run/router 0.0.0-experimental-3ce8d73c7 → 0.0.0-experimental-234a294e6

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## 1.17.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fog of War (unstable): Trigger a new `router.routes` identity/reflow during route patching ([#11740](https://github.com/remix-run/react-router/pull/11740))
8
+ - Fog of War (unstable): Fix initial matching when a splat route matches ([#11759](https://github.com/remix-run/react-router/pull/11759))
9
+
3
10
  ## 1.17.0
4
11
 
5
12
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -5,5 +5,5 @@ export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, c
5
5
  export * from "./router";
6
6
  /** @internal */
7
7
  export type { RouteManifest as UNSAFE_RouteManifest } from "./utils";
8
- export { DeferredData as UNSAFE_DeferredData, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, convertRouteMatchToUiMatch as UNSAFE_convertRouteMatchToUiMatch, getResolveToMatches as UNSAFE_getResolveToMatches, } from "./utils";
8
+ export { DeferredData as UNSAFE_DeferredData, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, convertRouteMatchToUiMatch as UNSAFE_convertRouteMatchToUiMatch, decodePath as UNSAFE_decodePath, getResolveToMatches as UNSAFE_getResolveToMatches, } from "./utils";
9
9
  export { invariant as UNSAFE_invariant, warning as UNSAFE_warning, } from "./history";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-3ce8d73c7
2
+ * @remix-run/router v0.0.0-experimental-234a294e6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1693,7 +1693,7 @@ function createRouter(init) {
1693
1693
  v7_partialHydration: false,
1694
1694
  v7_prependBasename: false,
1695
1695
  v7_relativeSplatPath: false,
1696
- unstable_skipActionErrorRevalidation: false
1696
+ v7_skipActionErrorRevalidation: false
1697
1697
  }, init.future);
1698
1698
  // Cleanup function for history
1699
1699
  let unlistenHistory = null;
@@ -1729,6 +1729,19 @@ function createRouter(init) {
1729
1729
  [route.id]: error
1730
1730
  };
1731
1731
  }
1732
+
1733
+ // In SPA apps, if the user provided a patchRoutesOnMiss implementation and
1734
+ // our initial match is a splat route, clear them out so we run through lazy
1735
+ // discovery on hydration in case there's a more accurate lazy route match.
1736
+ // In SSR apps (with `hydrationData`), we expect that the server will send
1737
+ // up the proper matched routes so we don't want to run lazy discovery on
1738
+ // initial hydration and want to hydrate into the splat route.
1739
+ if (initialMatches && patchRoutesOnMissImpl && !init.hydrationData) {
1740
+ let fogOfWar = checkFogOfWar(initialMatches, dataRoutes, init.history.location.pathname);
1741
+ if (fogOfWar.active) {
1742
+ initialMatches = null;
1743
+ }
1744
+ }
1732
1745
  let initialized;
1733
1746
  if (!initialMatches) {
1734
1747
  // We need to run patchRoutesOnMiss in initialize()
@@ -2395,13 +2408,12 @@ function createRouter(init) {
2395
2408
  };
2396
2409
  } else if (discoverResult.type === "error") {
2397
2410
  let {
2398
- error,
2399
- notFoundMatches,
2400
- route
2411
+ boundaryId,
2412
+ error
2401
2413
  } = handleDiscoverRouteError(location.pathname, discoverResult);
2402
2414
  return {
2403
- matches: notFoundMatches,
2404
- pendingActionResult: [route.id, {
2415
+ matches: discoverResult.partialMatches,
2416
+ pendingActionResult: [boundaryId, {
2405
2417
  type: ResultType.error,
2406
2418
  error
2407
2419
  }]
@@ -2534,15 +2546,14 @@ function createRouter(init) {
2534
2546
  };
2535
2547
  } else if (discoverResult.type === "error") {
2536
2548
  let {
2537
- error,
2538
- notFoundMatches,
2539
- route
2549
+ boundaryId,
2550
+ error
2540
2551
  } = handleDiscoverRouteError(location.pathname, discoverResult);
2541
2552
  return {
2542
- matches: notFoundMatches,
2553
+ matches: discoverResult.partialMatches,
2543
2554
  loaderData: {},
2544
2555
  errors: {
2545
- [route.id]: error
2556
+ [boundaryId]: error
2546
2557
  }
2547
2558
  };
2548
2559
  } else if (!discoverResult.matches) {
@@ -2563,7 +2574,7 @@ function createRouter(init) {
2563
2574
  }
2564
2575
  }
2565
2576
  let routesToUse = inFlightDataRoutes || dataRoutes;
2566
- let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, activeSubmission, location, future.v7_partialHydration && initialHydration === true, future.unstable_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult);
2577
+ let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, activeSubmission, location, future.v7_partialHydration && initialHydration === true, future.v7_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult);
2567
2578
 
2568
2579
  // Cancel pending deferreds for no-longer-matched routes or routes we're
2569
2580
  // about to reload. Note that if this is an action reload we would have
@@ -2898,7 +2909,7 @@ function createRouter(init) {
2898
2909
  fetchReloadIds.set(key, loadId);
2899
2910
  let loadFetcher = getLoadingFetcher(submission, actionResult.data);
2900
2911
  state.fetchers.set(key, loadFetcher);
2901
- let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, submission, nextLocation, false, future.unstable_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, [match.route.id, actionResult]);
2912
+ let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, submission, nextLocation, false, future.v7_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, [match.route.id, actionResult]);
2902
2913
 
2903
2914
  // Put all revalidating fetchers into the loading state, except for the
2904
2915
  // current fetcher which we want to keep in it's current loading state which
@@ -3418,18 +3429,13 @@ function createRouter(init) {
3418
3429
  };
3419
3430
  }
3420
3431
  function handleDiscoverRouteError(pathname, discoverResult) {
3421
- let matches = discoverResult.partialMatches;
3422
- let route = matches[matches.length - 1].route;
3423
- let error = getInternalRouterError(400, {
3424
- type: "route-discovery",
3425
- routeId: route.id,
3426
- pathname,
3427
- message: discoverResult.error != null && "message" in discoverResult.error ? discoverResult.error : String(discoverResult.error)
3428
- });
3429
3432
  return {
3430
- notFoundMatches: matches,
3431
- route,
3432
- error
3433
+ boundaryId: findNearestBoundary(discoverResult.partialMatches).route.id,
3434
+ error: getInternalRouterError(400, {
3435
+ type: "route-discovery",
3436
+ pathname,
3437
+ message: discoverResult.error != null && "message" in discoverResult.error ? discoverResult.error : String(discoverResult.error)
3438
+ })
3433
3439
  };
3434
3440
  }
3435
3441
  function cancelActiveDeferreds(predicate) {
@@ -3505,7 +3511,7 @@ function createRouter(init) {
3505
3511
  };
3506
3512
  } else {
3507
3513
  let leafRoute = matches[matches.length - 1].route;
3508
- if (leafRoute.path === "*") {
3514
+ if (leafRoute.path && (leafRoute.path === "*" || leafRoute.path.endsWith("/*"))) {
3509
3515
  // If we matched a splat, it might only be because we haven't yet fetched
3510
3516
  // the children that would match with a higher score, so let's fetch
3511
3517
  // around and find out
@@ -3604,24 +3610,10 @@ function createRouter(init) {
3604
3610
  manifest = {};
3605
3611
  inFlightDataRoutes = convertRoutesToDataRoutes(newRoutes, mapRouteProperties, undefined, manifest);
3606
3612
  }
3607
-
3608
- // single-patch implementation:
3609
- // router.patchRoutes(parentId, children);
3610
- //
3611
- // batch-patch implementation:
3612
- // router.patchRoutes((patch) => {
3613
- // patch(parentId1, children1);
3614
- // patch(parentId2, children2);
3615
- // patch(parentId3, children3);
3616
- // });
3617
- function patchRoutes(routeIdOrCb, children) {
3613
+ function patchRoutes(routeId, children) {
3618
3614
  let isNonHMR = inFlightDataRoutes == null;
3619
3615
  let routesToUse = inFlightDataRoutes || dataRoutes;
3620
- if (typeof routeIdOrCb === "function") {
3621
- routeIdOrCb((r, c) => patchRoutesImpl(r, c, routesToUse, manifest, mapRouteProperties));
3622
- } else if (typeof routeIdOrCb === "string" && children != null) {
3623
- patchRoutesImpl(routeIdOrCb, children, routesToUse, manifest, mapRouteProperties);
3624
- }
3616
+ patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties);
3625
3617
 
3626
3618
  // If we are not in the middle of an HMR revalidation and we changed the
3627
3619
  // routes, provide a new identity and trigger a reflow via `updateState`
@@ -4365,7 +4357,7 @@ function getMatchesToLoad(history, state, matches, submission, location, isIniti
4365
4357
  nextParams: nextRouteMatch.params
4366
4358
  }, submission, {
4367
4359
  actionResult,
4368
- unstable_actionStatus: actionStatus,
4360
+ actionStatus,
4369
4361
  defaultShouldRevalidate: shouldSkipRevalidation ? false :
4370
4362
  // Forced revalidation due to submission, useRevalidator, or X-Remix-Revalidate
4371
4363
  isRevalidationRequired || currentUrl.pathname + currentUrl.search === nextUrl.pathname + nextUrl.search ||
@@ -4430,7 +4422,7 @@ function getMatchesToLoad(history, state, matches, submission, location, isIniti
4430
4422
  nextParams: matches[matches.length - 1].params
4431
4423
  }, submission, {
4432
4424
  actionResult,
4433
- unstable_actionStatus: actionStatus,
4425
+ actionStatus,
4434
4426
  defaultShouldRevalidate: shouldSkipRevalidation ? false : isRevalidationRequired
4435
4427
  }));
4436
4428
  }
@@ -5076,7 +5068,7 @@ function getInternalRouterError(status, _temp5) {
5076
5068
  if (status === 400) {
5077
5069
  statusText = "Bad Request";
5078
5070
  if (type === "route-discovery") {
5079
- errorMessage = "Unable to match URL \"" + pathname + "\" - the `children()` function for " + ("route `" + routeId + "` threw the following error:\n" + message);
5071
+ errorMessage = "Unable to match URL \"" + pathname + "\" - the `unstable_patchRoutesOnMiss()` " + ("function threw the following error:\n" + message);
5080
5072
  } else if (method && pathname && routeId) {
5081
5073
  errorMessage = "You made a " + method + " request to \"" + pathname + "\" but " + ("did not provide a `loader` for route \"" + routeId + "\", ") + "so there is no way to handle the request.";
5082
5074
  } else if (type === "defer-action") {
@@ -5418,6 +5410,7 @@ exports.UNSAFE_DeferredData = DeferredData;
5418
5410
  exports.UNSAFE_ErrorResponseImpl = ErrorResponseImpl;
5419
5411
  exports.UNSAFE_convertRouteMatchToUiMatch = convertRouteMatchToUiMatch;
5420
5412
  exports.UNSAFE_convertRoutesToDataRoutes = convertRoutesToDataRoutes;
5413
+ exports.UNSAFE_decodePath = decodePath;
5421
5414
  exports.UNSAFE_getResolveToMatches = getResolveToMatches;
5422
5415
  exports.UNSAFE_invariant = invariant;
5423
5416
  exports.UNSAFE_warning = warning;