Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: collectAppPageSegments (#73908)
This refactors `collectAppPageSegments` to be more efficient especially when dealing with multiple parallel routes, where the number of combinations of segments can drastically increase how many segments are returned per route. Previously this function only considered the `children` parallel route. When it was updated to consider all possible parallel routes in #73358, this had the unintended side effect of increasing the amount of duplicate segments this function would have to process. We only need to return unique segments discovered from a particular loader tree (representing a page), as opposed to the same segment as many times as it might appear across all parallel routes. This PR uses a map to track unique segments with a composite key used to identify the discovered segments. Additionally, this refactors the function to be iterative rather than recursive. We keep track of a queue of segments to be processed (a tuple of `[loaderTree, segments]`), and as we discover new parallel route paths, we process the queue further. Fixes #73793 Closes #73871 (h/t to @icyJoseph for identifying the cause of the memory consumption)
- Loading branch information