@remix-run/router 0.0.0-experimental-abead7ae1 → 0.0.0-experimental-e157216e3

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction as unstable_DataStrategyFunction, DataStrategyFunctionArgs as unstable_DataStrategyFunctionArgs, DataStrategyMatch as unstable_DataStrategyMatch, ErrorResponse, FormEncType, FormMethod, HandlerResult as unstable_HandlerResult, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, } from "./utils";
1
+ export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction as unstable_DataStrategyFunction, DataStrategyFunctionArgs as unstable_DataStrategyFunctionArgs, DataStrategyMatch as unstable_DataStrategyMatch, ErrorResponse, FormEncType, FormMethod, HandlerResult as unstable_HandlerResult, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, AgnosticPatchRoutesOnMissFunction as unstable_AgnosticPatchRoutesOnMissFunction, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, } from "./utils";
2
2
  export { AbortedDeferredError, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, resolvePath, resolveTo, stripBasename, } from "./utils";
3
3
  export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
4
4
  export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, parsePath, } from "./history";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-abead7ae1
2
+ * @remix-run/router v0.0.0-experimental-e157216e3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -751,15 +751,9 @@ function matchRoutes(routes, locationArg, basename) {
751
751
  if (basename === void 0) {
752
752
  basename = "/";
753
753
  }
754
- return matchRoutesImpl(routes, locationArg, false, basename);
754
+ return matchRoutesImpl(routes, locationArg, basename, false);
755
755
  }
756
- function matchRoutesImpl(routes, locationArg, allowPartial, basename) {
757
- if (allowPartial === void 0) {
758
- allowPartial = false;
759
- }
760
- if (basename === void 0) {
761
- basename = "/";
762
- }
756
+ function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
763
757
  let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
764
758
  let pathname = stripBasename(location.pathname || "/", basename);
765
759
  if (pathname == null) {
@@ -1690,7 +1684,7 @@ function createRouter(init) {
1690
1684
  let inFlightDataRoutes;
1691
1685
  let basename = init.basename || "/";
1692
1686
  let dataStrategyImpl = init.unstable_dataStrategy || defaultDataStrategy;
1693
- let patchRoutesOnMissImpl = init.unstable_patchRoutesOnMiss || (() => Promise.resolve(null));
1687
+ let patchRoutesOnMissImpl = init.unstable_patchRoutesOnMiss;
1694
1688
 
1695
1689
  // Config driven behavior flags
1696
1690
  let future = _extends({
@@ -1720,7 +1714,7 @@ function createRouter(init) {
1720
1714
  let initialScrollRestored = init.hydrationData != null;
1721
1715
  let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
1722
1716
  let initialErrors = null;
1723
- if (initialMatches == null) {
1717
+ if (initialMatches == null && !patchRoutesOnMissImpl) {
1724
1718
  // If we do not match a user-provided-route, fall back to the root
1725
1719
  // to allow the error boundary to take over
1726
1720
  let error = getInternalRouterError(404, {
@@ -1736,13 +1730,15 @@ function createRouter(init) {
1736
1730
  };
1737
1731
  }
1738
1732
  let initialized;
1739
- let hasLazyRoutes = initialMatches.some(m => m.route.lazy);
1740
- let hasLoaders = initialMatches.some(m => m.route.loader);
1741
- if (hasLazyRoutes) {
1733
+ if (!initialMatches) {
1734
+ // We need to run patchRoutesOnMiss in initialize()
1735
+ initialized = false;
1736
+ initialMatches = [];
1737
+ } else if (initialMatches.some(m => m.route.lazy)) {
1742
1738
  // All initialMatches need to be loaded before we're ready. If we have lazy
1743
1739
  // functions around still then we'll need to run them in initialize()
1744
1740
  initialized = false;
1745
- } else if (!hasLoaders) {
1741
+ } else if (!initialMatches.some(m => m.route.loader)) {
1746
1742
  // If we've got no loaders to run, then we're good to go
1747
1743
  initialized = true;
1748
1744
  } else if (future.v7_partialHydration) {
@@ -3498,25 +3494,25 @@ function createRouter(init) {
3498
3494
  return null;
3499
3495
  }
3500
3496
  function checkFogOfWar(matches, routesToUse, pathname) {
3501
- if (!matches) {
3502
- let fogMatches = matchRoutesImpl(routesToUse, pathname, true, basename);
3503
- if (fogMatches) {
3504
- return {
3505
- active: true,
3506
- matches: fogMatches
3507
- };
3508
- }
3509
- } else {
3510
- let leafRoute = matches[matches.length - 1].route;
3511
- if (leafRoute.path === "*") {
3512
- // If we matched a splat, it might only be because we haven't yet fetched
3513
- // the children that would match with a higher score, so let's fetch
3514
- // around and find out
3515
- let partialMatches = matchRoutesImpl(routesToUse, pathname, true, basename);
3497
+ if (patchRoutesOnMissImpl) {
3498
+ if (!matches) {
3499
+ let fogMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
3516
3500
  return {
3517
3501
  active: true,
3518
- matches: partialMatches
3502
+ matches: fogMatches || []
3519
3503
  };
3504
+ } else {
3505
+ let leafRoute = matches[matches.length - 1].route;
3506
+ if (leafRoute.path === "*") {
3507
+ // If we matched a splat, it might only be because we haven't yet fetched
3508
+ // the children that would match with a higher score, so let's fetch
3509
+ // around and find out
3510
+ let partialMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
3511
+ return {
3512
+ active: true,
3513
+ matches: partialMatches
3514
+ };
3515
+ }
3520
3516
  }
3521
3517
  }
3522
3518
  return {
@@ -3526,10 +3522,10 @@ function createRouter(init) {
3526
3522
  }
3527
3523
  async function discoverRoutes(matches, pathname, signal) {
3528
3524
  let partialMatches = matches;
3529
- let route = partialMatches[partialMatches.length - 1].route;
3525
+ let route = partialMatches.length > 0 ? partialMatches[partialMatches.length - 1].route : null;
3530
3526
  while (true) {
3531
3527
  try {
3532
- await loadLazyRouteChildren(route, patchRoutesOnMissImpl, pathname, partialMatches, manifest, mapRouteProperties, pendingPatchRoutes, signal);
3528
+ await loadLazyRouteChildren(route, patchRoutesOnMissImpl, pathname, partialMatches, dataRoutes || inFlightDataRoutes, manifest, mapRouteProperties, pendingPatchRoutes, signal);
3533
3529
  if (signal.aborted) {
3534
3530
  return {
3535
3531
  type: "aborted"
@@ -3569,7 +3565,7 @@ function createRouter(init) {
3569
3565
  }
3570
3566
  }
3571
3567
  }
3572
- let newPartialMatches = matchRoutesImpl(routesToUse, pathname, true, basename);
3568
+ let newPartialMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
3573
3569
 
3574
3570
  // Loop detection if we find the same partials after a run through patchRoutesOnMiss
3575
3571
  if (!newPartialMatches || partialMatches.map(m => m.route.id).join("-") === newPartialMatches.map(m => m.route.id).join("-")) {
@@ -3634,7 +3630,7 @@ function createRouter(init) {
3634
3630
  getBlocker,
3635
3631
  deleteBlocker,
3636
3632
  patchRoutes(routeId, children) {
3637
- return patchRoutes(routeId, children, manifest, mapRouteProperties);
3633
+ return patchRoutes(routeId, children, dataRoutes || inFlightDataRoutes, manifest, mapRouteProperties);
3638
3634
  },
3639
3635
  _internalFetchControllers: fetchControllers,
3640
3636
  _internalActiveDeferreds: activeDeferreds,
@@ -4456,12 +4452,12 @@ function shouldRevalidateLoader(loaderMatch, arg) {
4456
4452
  * Idempotent utility to execute route.children() method to lazily load route
4457
4453
  * definitions and update the routes/routeManifest
4458
4454
  */
4459
- async function loadLazyRouteChildren(route, patchRoutesOnMissImpl, path, matches, manifest, mapRouteProperties, pendingRouteChildren, signal) {
4455
+ async function loadLazyRouteChildren(route, patchRoutesOnMissImpl, path, matches, routes, manifest, mapRouteProperties, pendingRouteChildren, signal) {
4460
4456
  let key = [path, ...matches.map(m => m.route.id)].join("-");
4461
4457
  let pending = pendingRouteChildren.get(key);
4462
4458
  let children = null;
4463
4459
  if (!pending) {
4464
- let maybePromise = patchRoutesOnMissImpl(path, matches);
4460
+ let maybePromise = patchRoutesOnMissImpl(path, matches, (r, c) => patchRoutes(r, c, routes, manifest, mapRouteProperties));
4465
4461
  if (isPromise(maybePromise)) {
4466
4462
  pending = maybePromise;
4467
4463
  pendingRouteChildren.set(key, pending);
@@ -4474,20 +4470,30 @@ async function loadLazyRouteChildren(route, patchRoutesOnMissImpl, path, matches
4474
4470
  children = await pending;
4475
4471
  }
4476
4472
  if (children && !signal.aborted) {
4477
- patchRoutes(route.id, children, manifest, mapRouteProperties);
4473
+ if (route) {
4474
+ patchRoutes(route.id, children, routes, manifest, mapRouteProperties);
4475
+ } else {
4476
+ warning(false, "You cannot return routes from `patchRoutesOnMiss` when there were no " + "partial matches, since React Router doesn't know where to patch the " + "routes. Please use `patch(routeId, children)` instead.");
4477
+ }
4478
4478
  }
4479
4479
  } finally {
4480
4480
  pendingRouteChildren.delete(key);
4481
4481
  }
4482
4482
  }
4483
- function patchRoutes(routeId, children, manifest, mapRouteProperties) {
4484
- let route = manifest[routeId];
4485
- invariant(route, "No route found to patch children into: routeId = " + routeId);
4486
- let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, [routeId, "patch"], manifest);
4487
- if (route.children) {
4488
- route.children.push(...dataChildren);
4483
+ function patchRoutes(routeId, children, routes, manifest, mapRouteProperties) {
4484
+ if (routeId) {
4485
+ var _route$children;
4486
+ let route = manifest[routeId];
4487
+ invariant(route, "No route found to patch children into: routeId = " + routeId);
4488
+ let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, [routeId, "patch", String(((_route$children = route.children) == null ? void 0 : _route$children.length) || "0")], manifest);
4489
+ if (route.children) {
4490
+ route.children.push(...dataChildren);
4491
+ } else {
4492
+ route.children = dataChildren;
4493
+ }
4489
4494
  } else {
4490
- route.children = dataChildren;
4495
+ let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, ["patch", String(routes.length || "0")], manifest);
4496
+ routes.push(...dataChildren);
4491
4497
  }
4492
4498
  }
4493
4499