Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: refactor collectAppPageSegments #73996

Merged
merged 1 commit into from
Dec 16, 2024
Merged

Conversation

ztanner
Copy link
Member

@ztanner ztanner commented Dec 16, 2024

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)
@ijjk ijjk added created-by: Next.js team PRs by the Next.js team. type: next labels Dec 16, 2024
@ijjk
Copy link
Member

ijjk commented Dec 16, 2024

Tests Passed

@ztanner ztanner marked this pull request as ready for review December 16, 2024 21:52
@ztanner ztanner requested a review from ijjk December 16, 2024 21:52
@ztanner ztanner merged commit e83ab18 into next-15-0 Dec 16, 2024
101 of 110 checks passed
@ztanner ztanner deleted the zt/backport-73908 branch December 16, 2024 21:57
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants