Skip to content

fix: preserve bind:this values in effect teardown#18159

Open
RazinShafayet2007 wants to merge 9 commits into
sveltejs:mainfrom
RazinShafayet2007:fix/bind-this-teardown
Open

fix: preserve bind:this values in effect teardown#18159
RazinShafayet2007 wants to merge 9 commits into
sveltejs:mainfrom
RazinShafayet2007:fix/bind-this-teardown

Conversation

@RazinShafayet2007
Copy link
Copy Markdown
Contributor

Fixes #18150

bind:this was clearing its bound state during destroy-time teardown, and that internal update(null, ...parts) write was overwriting the old-value snapshot that $effect cleanup reads rely on. As a result, cleanup code reading a bind:this state directly could see null instead of the last bound element or component. This fixes that by preserving the pre-null teardown values for the signals used by the binding expression before clearing the binding, so effect teardowns continue to see the expected last value while keeping the existing bind:this cleanup behavior intact.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 29, 2026

🦋 Changeset detected

Latest commit: 4d1ce5a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarification needed for bind:this and $effect teardown

1 participant