@remix-run/router 0.0.0-experimental-b3c9fc11b → 0.0.0-experimental-dc307bdd5

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 v0.0.0-experimental-b3c9fc11b
2
+ * @remix-run/router v0.0.0-experimental-dc307bdd5
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1728,6 +1728,10 @@ function createRouter(init) {
1728
1728
  let unlistenHistory = null;
1729
1729
  // Externally-provided functions to call on all state changes
1730
1730
  let subscribers = new Set();
1731
+ // FIFO queue of previously discovered routes to prevent re-calling on
1732
+ // subsequent navigations to the same path
1733
+ let discoveredRoutesMaxSize = 1000;
1734
+ let discoveredRoutes = new Set();
1731
1735
  // Externally-provided object to hold scroll restoration locations during routing
1732
1736
  let savedScrollPositions = null;
1733
1737
  // Externally-provided function to get scroll restoration keys
@@ -3541,6 +3545,15 @@ function createRouter(init) {
3541
3545
  }
3542
3546
  function checkFogOfWar(matches, routesToUse, pathname) {
3543
3547
  if (patchRoutesOnMissImpl) {
3548
+ // Don't bother re-calling patchRouteOnMiss for a path we've already
3549
+ // processed. the last execution would have patched the route tree
3550
+ // accordingly so `matches` here are already accurate.
3551
+ if (discoveredRoutes.has(pathname)) {
3552
+ return {
3553
+ active: false,
3554
+ matches
3555
+ };
3556
+ }
3544
3557
  if (!matches) {
3545
3558
  let fogMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
3546
3559
  return {
@@ -3596,6 +3609,7 @@ function createRouter(init) {
3596
3609
  }
3597
3610
  let newMatches = matchRoutes(routesToUse, pathname, basename);
3598
3611
  if (newMatches) {
3612
+ addToFifoQueue(pathname, discoveredRoutes);
3599
3613
  return {
3600
3614
  type: "success",
3601
3615
  matches: newMatches
@@ -3605,6 +3619,7 @@ function createRouter(init) {
3605
3619
 
3606
3620
  // Avoid loops if the second pass results in the same partial matches
3607
3621
  if (!newPartialMatches || partialMatches.length === newPartialMatches.length && partialMatches.every((m, i) => m.route.id === newPartialMatches[i].route.id)) {
3622
+ addToFifoQueue(pathname, discoveredRoutes);
3608
3623
  return {
3609
3624
  type: "success",
3610
3625
  matches: null
@@ -3613,6 +3628,13 @@ function createRouter(init) {
3613
3628
  partialMatches = newPartialMatches;
3614
3629
  }
3615
3630
  }
3631
+ function addToFifoQueue(path, queue) {
3632
+ if (queue.size >= discoveredRoutesMaxSize) {
3633
+ let first = queue.values().next().value;
3634
+ queue.delete(first);
3635
+ }
3636
+ queue.add(path);
3637
+ }
3616
3638
  function _internalSetRoutes(newRoutes) {
3617
3639
  manifest = {};
3618
3640
  inFlightDataRoutes = convertRoutesToDataRoutes(newRoutes, mapRouteProperties, undefined, manifest);