fix: bind:this on changing transitioning element #8930
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 #8891
When an outro starts, a bind:this variable is now nulled immediately, instead of when the element is destroyed. This is a breaking change.
This makes the behaviour consistent with, and appropriate for, the case where the bind:this value is swapping from one transitioning element to another (such as in an if/else block), and avoids the bug in that situation where the outroing component nulls the bind:this variable which has since been bound to another element. This bug specifically breaks snapshotting in SvelteKit when using transitions on pages.
The new
binding-this-transition-js-if-else-block
test highlights the bug most simply (in practice the bug is more subtle - since the unwanted nulling doesn't cause the element to be invalidated, it isn't usually until some other change occurs that the change in the value is reactively apparent).Things to do still (if appropriate):
bind_this.js
, the branch for when there are contextual_dependencies, would likely need similar changes if this approach is appropriate.Because this pull request affects code that is possibly undergoing considerable change for Svelte 5, as well as it being a breaking change, it may be appropriate for this pull request to inform that process rather than be used directly.