fix: lazily create inTransition external source to prevent use-after-dispose#2589
Open
veeceey wants to merge 2 commits intosolidjs:mainfrom
Open
fix: lazily create inTransition external source to prevent use-after-dispose#2589veeceey wants to merge 2 commits intosolidjs:mainfrom
veeceey wants to merge 2 commits intosolidjs:mainfrom
Conversation
…dispose The inTransition external source was eagerly created and disposed after each transition resolved. When a subsequent transition started, the disposed source was still referenced, causing errors when .track() was called on it. This change makes inTransition lazily initialized on first use during a transition and properly re-created after disposal. Fixes solidjs#2275.
🦋 Changeset detectedLatest commit: 1660690 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 |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Fixes #2275
Problem
When using
enableExternalSourcewith transitions and a suspense context, theinTransitionexternal source is created eagerly during computation setup and disposed after the transition promise resolves. If a subsequent transition starts later, the code tries to call.track()on the already-disposedinTransitioninstance, which throws an error.The reporter's workaround was to ignore
dispose()calls for inTransition computations, which leaks memory.Fix
Instead of eagerly creating
inTransitionupfront and holding a single reference forever, this change:inTransitionasundefinedundefinedThis matches the approach suggested by @milomg in the issue comments. The key insight is that the
inTransitionsource only needs to exist while a transition is actively running - there's no reason to keep a stale/disposed instance around between transitions.Test
Added a test that sets up an external source with a suspense context, runs two sequential transitions, and verifies the second transition doesn't throw due to the disposed inTransition source.