fix: release lazy() resource and suspense contexts on dispose#2730
Open
MRJCrunch wants to merge 1 commit into
Open
fix: release lazy() resource and suspense contexts on dispose#2730MRJCrunch wants to merge 1 commit into
MRJCrunch wants to merge 1 commit into
Conversation
Nested lazy() components leaked the previous tree across navigation. lazy() cached its createResource accessor in a module-scoped variable, pinning the resource's reactive graph for the app lifetime, and createResource never released its suspense contexts on disposal. With stacked lazy() boundaries that kept disposed component trees (and their detached DOM) reachable, so they were never garbage collected. lazy() now clears the module-scoped accessor on cleanup (the import promise stays cached, so no refetch), and createResource clears its suspense contexts and pending transition promise when its owner is disposed.
🦋 Changeset detectedLatest commit: 51d4779 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lazy()components leak the previous component tree across navigation whenlazy()boundaries are nested.Root cause
lazy()caches itscreateResourceaccessor in a module-scopedcompvariable, which pins the resource's reactive graph for the lifetime of the app.createResourcenever releases its Suspensecontextsset (nor the pending transition promise) on disposal.When
lazy()boundaries are nested (e.g. a router where a lazy route renders an outlet that contains another lazy route), the inner resource's reactive nodes are parented under the outer, module-pinned graph. Because that graph is never released and the resource never clears its contexts on dispose, the disposed component subtree — and its detached DOM — stays reachable and is never garbage collected. Each navigation leaks another tree.A single
lazy()boundary does not leak; only nested/stackedlazy()does.Fix
lazy()clears the module-scoped accessor (comp) inonCleanup. The import promisepstays cached, so unmount/remount does not refetch the chunk.createResourceclears its Suspensecontexts(decrementing each) and removes its pending promise from the activeTransitionwhen its owner is disposed. Guarded byif (Owner)so resources created outside a reactive root behave exactly as before.Verification
pnpm build+pnpm test: 469/469 tests pass, no new warnings.A changeset is included (
solid-jspatch).