Dispose dev child entries after their parents are disposed
The webpack dev server never disposed CHILD_ENTRY records in
on-demand-entry-handler (a TODO-APP): disposeInactiveEntries skipped them
entirely, so every visited app page left its client-side flight entry in
the entries map and in the client webpack compilation for the lifetime of
the dev server, accumulating compilation memory during long dev sessions
(#54708).
A child entry is injected by its parent entries (e.g. the client flight
entry of an app page) and is needed exactly as long as at least one of
them. This changes the disposal lifecycle in three places:
- disposeInactiveEntries recomputes each child entry's disposal state
once per pass from the bundle paths of the active ENTRY records:
scheduled once no active parent remains, and cleared again if a parent
is revived. Recomputing instead of permanently pruning the parent set
matters because the disposal flag is only pending until the disposal
machinery runs.
- hot-reloader-webpack's entry computation, which deletes entries whose
disposal flag is set, now consults live parent state for child entries:
a child whose parent was revived after the last disposal pass is kept
even while it still carries a stale disposal flag.
- hot-reloader-rspack rehydrates child parentEntries back into Sets when
reading built-entries.json: JSON.stringify serializes Sets as plain
objects, which would otherwise crash disposal iteration on restart.
Only ENTRY records count as parents: a child entry shares its parent
bundle path, so considering every record would keep the parent set alive
through the child itself.
The pre-existing open PR #89587 attempted this fix but compared parent
names against the bundle paths of all undisposed records including the
child itself, which always matches and therefore never disposes anything.
Adds unit tests covering: stale-parent disposal across passes, removal of
gone parents, empty parent sets, shared children with mixed parent
states, revival of a parent scheduled for disposal, active-parent
computation, and middleware/instrumentation exemptions.
Verified end to end in a webpack dev server instrumented to dump the
entries map per pass: after maxInactiveAge the parent entries of three
visited app pages were scheduled, their child entries were scheduled in
the following passes with the parent links kept intact, and the next
compilation removed all of them from the map; re-visiting a disposed page
revived its entries and rendered fine.
Fixes #54708
Co-Authored-By:
Marcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
Showing
Please
register
or
sign in
to comment