@remix-run/router 0.0.0-experimental-52e9b8eb3 → 0.0.0-experimental-edf416237

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, PatchRoutesOnMissFunction as unstable_PatchRoutesOnMissFunction, 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-52e9b8eb3
2
+ * @remix-run/router v0.0.0-experimental-edf416237
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -735,15 +735,7 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath, manif
735
735
  });
736
736
  manifest[id] = pathOrLayoutRoute;
737
737
  if (route.children) {
738
- if (typeof route.children === "function") {
739
- let loadChildren = route.children;
740
- pathOrLayoutRoute.children = async () => {
741
- let children = await loadChildren();
742
- return convertRoutesToDataRoutes(children, mapRouteProperties, treePath, manifest);
743
- };
744
- } else {
745
- pathOrLayoutRoute.children = convertRoutesToDataRoutes(route.children, mapRouteProperties, treePath, manifest);
746
- }
738
+ pathOrLayoutRoute.children = convertRoutesToDataRoutes(route.children, mapRouteProperties, treePath, manifest);
747
739
  }
748
740
  return pathOrLayoutRoute;
749
741
  }
@@ -759,21 +751,15 @@ function matchRoutes(routes, locationArg, basename) {
759
751
  if (basename === void 0) {
760
752
  basename = "/";
761
753
  }
762
- return matchRoutesImpl(routes, locationArg, false, basename);
754
+ return matchRoutesImpl(routes, locationArg, basename, false);
763
755
  }
764
- function matchRoutesImpl(routes, locationArg, allowPartial, basename) {
765
- if (allowPartial === void 0) {
766
- allowPartial = false;
767
- }
768
- if (basename === void 0) {
769
- basename = "/";
770
- }
756
+ function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
771
757
  let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
772
758
  let pathname = stripBasename(location.pathname || "/", basename);
773
759
  if (pathname == null) {
774
760
  return null;
775
761
  }
776
- let branches = flattenRoutes(routes, allowPartial);
762
+ let branches = flattenRoutes(routes);
777
763
  rankRouteBranches(branches);
778
764
  let matches = null;
779
765
  for (let i = 0; matches == null && i < branches.length; ++i) {
@@ -802,7 +788,7 @@ function convertRouteMatchToUiMatch(match, loaderData) {
802
788
  handle: route.handle
803
789
  };
804
790
  }
805
- function flattenRoutes(routes, allowPartial, branches, parentsMeta, parentPath) {
791
+ function flattenRoutes(routes, branches, parentsMeta, parentPath) {
806
792
  if (branches === void 0) {
807
793
  branches = [];
808
794
  }
@@ -834,15 +820,12 @@ function flattenRoutes(routes, allowPartial, branches, parentsMeta, parentPath)
834
820
  // Our types know better, but runtime JS may not!
835
821
  // @ts-expect-error
836
822
  route.index !== true, "Index routes must not have child routes. Please remove " + ("all child routes from route path \"" + path + "\"."));
837
- invariant(typeof route.children !== "function", "Route children must be resolved prior to calling flattenRoutes");
838
- flattenRoutes(route.children, allowPartial, branches, routesMeta, path);
823
+ flattenRoutes(route.children, branches, routesMeta, path);
839
824
  }
840
825
 
841
826
  // Routes without a path shouldn't ever match by themselves unless they are
842
827
  // index routes, so don't add them to the list of possible branches.
843
- // When partial matching we do want these to match so we can detect their
844
- // async children() functions
845
- if (route.path == null && !route.index && !allowPartial) {
828
+ if (route.path == null && !route.index) {
846
829
  return;
847
830
  }
848
831
  branches.push({
@@ -967,10 +950,7 @@ function matchRouteBranch(branch, pathname, allowPartial) {
967
950
  end
968
951
  }, remainingPathname);
969
952
  let route = meta.route;
970
-
971
- // If this route has a `children()` function then allow partial matching
972
- // up to this point if requested
973
- if (!match && end && allowPartial && typeof route.children === "function") {
953
+ if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) {
974
954
  match = matchPath({
975
955
  path: meta.relativePath,
976
956
  caseSensitive: meta.caseSensitive,
@@ -1704,6 +1684,8 @@ function createRouter(init) {
1704
1684
  let inFlightDataRoutes;
1705
1685
  let basename = init.basename || "/";
1706
1686
  let dataStrategyImpl = init.unstable_dataStrategy || defaultDataStrategy;
1687
+ let patchRoutesOnMissImpl = init.unstable_patchRoutesOnMiss;
1688
+
1707
1689
  // Config driven behavior flags
1708
1690
  let future = _extends({
1709
1691
  v7_fetcherPersist: false,
@@ -1881,8 +1863,9 @@ function createRouter(init) {
1881
1863
  // we don't need to update UI state if they change
1882
1864
  let blockerFunctions = new Map();
1883
1865
 
1884
- // Map of pending children() function executions so that we only kick them off once
1885
- let pendingRouteChildren = new Map();
1866
+ // Map of pending patchRoutesOnMiss() promises (keyed by path/matches) so
1867
+ // that we only kick them off once for a given combo
1868
+ let pendingPatchRoutes = new Map();
1886
1869
 
1887
1870
  // Flag to ignore the next history update, so we can revert the URL change on
1888
1871
  // a POP navigation that was blocked by the user without touching router state
@@ -2272,27 +2255,10 @@ function createRouter(init) {
2272
2255
  let routesToUse = inFlightDataRoutes || dataRoutes;
2273
2256
  let loadingNavigation = opts && opts.overrideNavigation;
2274
2257
  let matches = matchRoutes(routesToUse, location, basename);
2275
- let isFogOfWar = false;
2276
2258
  let flushSync = (opts && opts.flushSync) === true;
2277
- if (!matches) {
2278
- let fogMatches = matchRoutesImpl(routesToUse, location, true, basename);
2279
- if (fogMatches) {
2280
- isFogOfWar = true;
2281
- matches = fogMatches;
2282
- }
2283
- } else {
2284
- let leafRoute = matches[matches.length - 1].route;
2285
- if (leafRoute.path && leafRoute.path.length > 0 && typeof leafRoute.children === "function") {
2286
- // This route _might_ have an index child so we need to
2287
- // fetch around and find out
2288
- isFogOfWar = true;
2289
- }
2290
- if (leafRoute.path === "*") {
2291
- // If we matched a splat, it might only be because we haven't loaded
2292
- // the children that would match with a higher score, so let's go the
2293
- // fog of war route to be sure
2294
- isFogOfWar = true;
2295
- }
2259
+ let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
2260
+ if (fogOfWar.active && fogOfWar.matches) {
2261
+ matches = fogOfWar.matches;
2296
2262
  }
2297
2263
 
2298
2264
  // Short circuit with a 404 on the root error boundary if we match nothing
@@ -2344,7 +2310,7 @@ function createRouter(init) {
2344
2310
  }];
2345
2311
  } else if (opts && opts.submission && isMutationMethod(opts.submission.formMethod)) {
2346
2312
  // Call action if we received an action submission
2347
- let actionResult = await handleAction(request, location, opts.submission, matches, isFogOfWar, {
2313
+ let actionResult = await handleAction(request, location, opts.submission, matches, fogOfWar.active, {
2348
2314
  replace: opts.replace,
2349
2315
  flushSync
2350
2316
  });
@@ -2373,7 +2339,7 @@ function createRouter(init) {
2373
2339
  loadingNavigation = getLoadingNavigation(location, opts.submission);
2374
2340
  flushSync = false;
2375
2341
  // No need to do fog of war matching again on loader execution
2376
- isFogOfWar = false;
2342
+ fogOfWar.active = false;
2377
2343
 
2378
2344
  // Create a GET request for the loaders
2379
2345
  request = createClientSideRequest(init.history, request.url, request.signal);
@@ -2385,7 +2351,7 @@ function createRouter(init) {
2385
2351
  matches: updatedMatches,
2386
2352
  loaderData,
2387
2353
  errors
2388
- } = await handleLoaders(request, location, matches, isFogOfWar, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, opts && opts.initialHydration === true, flushSync, pendingActionResult);
2354
+ } = await handleLoaders(request, location, matches, fogOfWar.active, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, opts && opts.initialHydration === true, flushSync, pendingActionResult);
2389
2355
  if (shortCircuited) {
2390
2356
  return;
2391
2357
  }
@@ -2766,6 +2732,10 @@ function createRouter(init) {
2766
2732
  let routesToUse = inFlightDataRoutes || dataRoutes;
2767
2733
  let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, href, future.v7_relativeSplatPath, routeId, opts == null ? void 0 : opts.relative);
2768
2734
  let matches = matchRoutes(routesToUse, normalizedPath, basename);
2735
+ let fogOfWar = checkFogOfWar(matches, routesToUse, normalizedPath);
2736
+ if (fogOfWar.active && fogOfWar.matches) {
2737
+ matches = fogOfWar.matches;
2738
+ }
2769
2739
  if (!matches) {
2770
2740
  setFetcherError(key, routeId, getInternalRouterError(404, {
2771
2741
  pathname: normalizedPath
@@ -2788,7 +2758,7 @@ function createRouter(init) {
2788
2758
  let match = getTargetMatch(matches, path);
2789
2759
  pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
2790
2760
  if (submission && isMutationMethod(submission.formMethod)) {
2791
- handleFetcherAction(key, routeId, path, match, matches, flushSync, submission);
2761
+ handleFetcherAction(key, routeId, path, match, matches, fogOfWar.active, flushSync, submission);
2792
2762
  return;
2793
2763
  }
2794
2764
 
@@ -2798,23 +2768,29 @@ function createRouter(init) {
2798
2768
  routeId,
2799
2769
  path
2800
2770
  });
2801
- handleFetcherLoader(key, routeId, path, match, matches, flushSync, submission);
2771
+ handleFetcherLoader(key, routeId, path, match, matches, fogOfWar.active, flushSync, submission);
2802
2772
  }
2803
2773
 
2804
2774
  // Call the action for the matched fetcher.submit(), and then handle redirects,
2805
2775
  // errors, and revalidation
2806
- async function handleFetcherAction(key, routeId, path, match, requestMatches, flushSync, submission) {
2776
+ async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, submission) {
2807
2777
  interruptActiveLoads();
2808
2778
  fetchLoadMatches.delete(key);
2809
- if (!match.route.action && !match.route.lazy) {
2810
- let error = getInternalRouterError(405, {
2811
- method: submission.formMethod,
2812
- pathname: path,
2813
- routeId: routeId
2814
- });
2815
- setFetcherError(key, routeId, error, {
2816
- flushSync
2817
- });
2779
+ function detectAndHandle405Error(m) {
2780
+ if (!m.route.action && !m.route.lazy) {
2781
+ let error = getInternalRouterError(405, {
2782
+ method: submission.formMethod,
2783
+ pathname: path,
2784
+ routeId: routeId
2785
+ });
2786
+ setFetcherError(key, routeId, error, {
2787
+ flushSync
2788
+ });
2789
+ return true;
2790
+ }
2791
+ return false;
2792
+ }
2793
+ if (!isFogOfWar && detectAndHandle405Error(match)) {
2818
2794
  return;
2819
2795
  }
2820
2796
 
@@ -2823,10 +2799,37 @@ function createRouter(init) {
2823
2799
  updateFetcherState(key, getSubmittingFetcher(submission, existingFetcher), {
2824
2800
  flushSync
2825
2801
  });
2826
-
2827
- // Call the action for the fetcher
2828
2802
  let abortController = new AbortController();
2829
2803
  let fetchRequest = createClientSideRequest(init.history, path, abortController.signal, submission);
2804
+ if (isFogOfWar) {
2805
+ let discoverResult = await discoverRoutes(requestMatches, path, fetchRequest.signal);
2806
+ if (discoverResult.type === "aborted") {
2807
+ return;
2808
+ } else if (discoverResult.type === "error") {
2809
+ let {
2810
+ error
2811
+ } = handleDiscoverRouteError(path, discoverResult);
2812
+ setFetcherError(key, routeId, error, {
2813
+ flushSync
2814
+ });
2815
+ return;
2816
+ } else if (!discoverResult.matches) {
2817
+ setFetcherError(key, routeId, getInternalRouterError(404, {
2818
+ pathname: path
2819
+ }), {
2820
+ flushSync
2821
+ });
2822
+ return;
2823
+ } else {
2824
+ requestMatches = discoverResult.matches;
2825
+ match = getTargetMatch(requestMatches, path);
2826
+ if (detectAndHandle405Error(match)) {
2827
+ return;
2828
+ }
2829
+ }
2830
+ }
2831
+
2832
+ // Call the action for the fetcher
2830
2833
  fetchControllers.set(key, abortController);
2831
2834
  let originatingLoadId = incrementingLoadId;
2832
2835
  let actionResults = await callDataStrategy("action", fetchRequest, [match], requestMatches);
@@ -2976,15 +2979,39 @@ function createRouter(init) {
2976
2979
  }
2977
2980
 
2978
2981
  // Call the matched loader for fetcher.load(), handling redirects, errors, etc.
2979
- async function handleFetcherLoader(key, routeId, path, match, matches, flushSync, submission) {
2982
+ async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, submission) {
2980
2983
  let existingFetcher = state.fetchers.get(key);
2981
2984
  updateFetcherState(key, getLoadingFetcher(submission, existingFetcher ? existingFetcher.data : undefined), {
2982
2985
  flushSync
2983
2986
  });
2984
-
2985
- // Call the loader for this fetcher route match
2986
2987
  let abortController = new AbortController();
2987
2988
  let fetchRequest = createClientSideRequest(init.history, path, abortController.signal);
2989
+ if (isFogOfWar) {
2990
+ let discoverResult = await discoverRoutes(matches, path, fetchRequest.signal);
2991
+ if (discoverResult.type === "aborted") {
2992
+ return;
2993
+ } else if (discoverResult.type === "error") {
2994
+ let {
2995
+ error
2996
+ } = handleDiscoverRouteError(path, discoverResult);
2997
+ setFetcherError(key, routeId, error, {
2998
+ flushSync
2999
+ });
3000
+ return;
3001
+ } else if (!discoverResult.matches) {
3002
+ setFetcherError(key, routeId, getInternalRouterError(404, {
3003
+ pathname: path
3004
+ }), {
3005
+ flushSync
3006
+ });
3007
+ return;
3008
+ } else {
3009
+ matches = discoverResult.matches;
3010
+ match = getTargetMatch(matches, path);
3011
+ }
3012
+ }
3013
+
3014
+ // Call the loader for this fetcher route match
2988
3015
  fetchControllers.set(key, abortController);
2989
3016
  let originatingLoadId = incrementingLoadId;
2990
3017
  let results = await callDataStrategy("loader", fetchRequest, [match], matches);
@@ -3464,13 +3491,40 @@ function createRouter(init) {
3464
3491
  }
3465
3492
  return null;
3466
3493
  }
3494
+ function checkFogOfWar(matches, routesToUse, pathname) {
3495
+ if (patchRoutesOnMissImpl) {
3496
+ if (!matches) {
3497
+ let fogMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
3498
+ return {
3499
+ active: true,
3500
+ matches: fogMatches || []
3501
+ };
3502
+ } else {
3503
+ let leafRoute = matches[matches.length - 1].route;
3504
+ if (leafRoute.path === "*") {
3505
+ // If we matched a splat, it might only be because we haven't yet fetched
3506
+ // the children that would match with a higher score, so let's fetch
3507
+ // around and find out
3508
+ let partialMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
3509
+ return {
3510
+ active: true,
3511
+ matches: partialMatches
3512
+ };
3513
+ }
3514
+ }
3515
+ }
3516
+ return {
3517
+ active: false,
3518
+ matches: null
3519
+ };
3520
+ }
3467
3521
  async function discoverRoutes(matches, pathname, signal) {
3468
3522
  let partialMatches = matches;
3469
- let route = partialMatches[partialMatches.length - 1].route;
3523
+ let route = partialMatches.length > 0 ? partialMatches[partialMatches.length - 1].route : null;
3470
3524
  while (true) {
3471
3525
  try {
3472
- await loadLazyRouteChildren(route, pendingRouteChildren);
3473
- if (signal != null && signal.aborted) {
3526
+ await loadLazyRouteChildren(route, patchRoutesOnMissImpl, pathname, partialMatches, dataRoutes || inFlightDataRoutes, manifest, mapRouteProperties, pendingPatchRoutes, signal);
3527
+ if (signal.aborted) {
3474
3528
  return {
3475
3529
  type: "aborted"
3476
3530
  };
@@ -3484,6 +3538,7 @@ function createRouter(init) {
3484
3538
  }
3485
3539
  let routesToUse = inFlightDataRoutes || dataRoutes;
3486
3540
  let newMatches = matchRoutes(routesToUse, pathname, basename);
3541
+ let matchedSplat = false;
3487
3542
  if (newMatches) {
3488
3543
  let leafRoute = newMatches[newMatches.length - 1].route;
3489
3544
  if (leafRoute.index) {
@@ -3493,29 +3548,40 @@ function createRouter(init) {
3493
3548
  matches: newMatches
3494
3549
  };
3495
3550
  }
3496
- if (leafRoute.path && leafRoute.path.length > 0 && leafRoute.path !== "*" &&
3497
- // Can't assume splats match higher?
3498
- typeof leafRoute.children !== "function") {
3499
- // If we found a path'd non-splat route without async children, we
3500
- // can stop.
3501
- // If it's a splat route, we can't be sure there's not a higher-scoring
3502
- // route down some partial Matches trail so we need to check that out
3503
- // If it has an async children() function we need to go down that road
3504
- // in case it has index or pathless children that may match
3551
+ if (leafRoute.path && leafRoute.path.length > 0) {
3552
+ if (leafRoute.path === "*") {
3553
+ // If we found a splat route, we can't be sure there's not a
3554
+ // higher-scoring route down some partial matches trail so we need
3555
+ // to check that out
3556
+ matchedSplat = true;
3557
+ } else {
3558
+ // If we found a non-splat route, we can stop
3559
+ return {
3560
+ type: "success",
3561
+ matches: newMatches
3562
+ };
3563
+ }
3564
+ }
3565
+ }
3566
+ let newPartialMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
3567
+
3568
+ // Loop detection if we find the same partials after a run through patchRoutesOnMiss
3569
+ if (!newPartialMatches || partialMatches.map(m => m.route.id).join("-") === newPartialMatches.map(m => m.route.id).join("-")) {
3570
+ // We are no longer partially matching anything new so this was either a
3571
+ // legit splat match above, or it's a 404
3572
+ if (matchedSplat) {
3505
3573
  return {
3506
3574
  type: "success",
3507
3575
  matches: newMatches
3508
3576
  };
3577
+ } else {
3578
+ return {
3579
+ type: "success",
3580
+ matches: null
3581
+ };
3509
3582
  }
3510
3583
  }
3511
- partialMatches = matchRoutesImpl(routesToUse, pathname, true, basename);
3512
- if (!partialMatches) {
3513
- // We are no longer partially matching so this is a legit 404
3514
- return {
3515
- type: "success",
3516
- matches: null
3517
- };
3518
- }
3584
+ partialMatches = newPartialMatches;
3519
3585
  route = partialMatches[partialMatches.length - 1].route;
3520
3586
  if (route.path === "*") {
3521
3587
  // The splat is still our most accurate partial, so run with it
@@ -3561,6 +3627,9 @@ function createRouter(init) {
3561
3627
  dispose,
3562
3628
  getBlocker,
3563
3629
  deleteBlocker,
3630
+ patchRoutes(routeId, children) {
3631
+ return patchRoutes(routeId, children, dataRoutes || inFlightDataRoutes, manifest, mapRouteProperties);
3632
+ },
3564
3633
  _internalFetchControllers: fetchControllers,
3565
3634
  _internalActiveDeferreds: activeDeferreds,
3566
3635
  // TODO: Remove setRoutes, it's temporary to avoid dealing with
@@ -4381,21 +4450,48 @@ function shouldRevalidateLoader(loaderMatch, arg) {
4381
4450
  * Idempotent utility to execute route.children() method to lazily load route
4382
4451
  * definitions and update the routes/routeManifest
4383
4452
  */
4384
- async function loadLazyRouteChildren(route, pendingRouteChildren) {
4385
- if (typeof route.children !== "function") {
4386
- return;
4387
- }
4388
- let pending = pendingRouteChildren.get(route.id);
4453
+ async function loadLazyRouteChildren(route, patchRoutesOnMissImpl, path, matches, routes, manifest, mapRouteProperties, pendingRouteChildren, signal) {
4454
+ let key = [path, ...matches.map(m => m.route.id)].join("-");
4455
+ let pending = pendingRouteChildren.get(key);
4456
+ let children = null;
4389
4457
  if (!pending) {
4390
- // convertRoutesToDataRoutes wraps the underlying children function to
4391
- // ensure returned routes are converted to data routes
4392
- pending = route.children();
4393
- pendingRouteChildren.set(route.id, pending);
4458
+ let maybePromise = patchRoutesOnMissImpl(path, matches, (r, c) => patchRoutes(r, c, routes, manifest, mapRouteProperties));
4459
+ if (isPromise(maybePromise)) {
4460
+ pending = maybePromise;
4461
+ pendingRouteChildren.set(key, pending);
4462
+ } else {
4463
+ children = maybePromise;
4464
+ }
4394
4465
  }
4395
4466
  try {
4396
- route.children = await pending;
4467
+ if (pending) {
4468
+ children = await pending;
4469
+ }
4470
+ if (children && !signal.aborted) {
4471
+ if (route) {
4472
+ patchRoutes(route.id, children, routes, manifest, mapRouteProperties);
4473
+ } else {
4474
+ 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.");
4475
+ }
4476
+ }
4397
4477
  } finally {
4398
- pendingRouteChildren.delete(route.id);
4478
+ pendingRouteChildren.delete(key);
4479
+ }
4480
+ }
4481
+ function patchRoutes(routeId, children, routes, manifest, mapRouteProperties) {
4482
+ if (routeId) {
4483
+ var _route$children;
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", String(((_route$children = route.children) == null ? void 0 : _route$children.length) || "0")], manifest);
4487
+ if (route.children) {
4488
+ route.children.push(...dataChildren);
4489
+ } else {
4490
+ route.children = dataChildren;
4491
+ }
4492
+ } else {
4493
+ let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, ["patch", String(routes.length || "0")], manifest);
4494
+ routes.push(...dataChildren);
4399
4495
  }
4400
4496
  }
4401
4497
 
@@ -5012,6 +5108,9 @@ function isHashChangeOnly(a, b) {
5012
5108
  // /page#hash -> /page
5013
5109
  return false;
5014
5110
  }
5111
+ function isPromise(val) {
5112
+ return typeof val === "object" && val != null && "then" in val;
5113
+ }
5015
5114
  function isHandlerResult(result) {
5016
5115
  return result != null && typeof result === "object" && "type" in result && "result" in result && (result.type === ResultType.data || result.type === ResultType.error);
5017
5116
  }