Skip to content

fix: freeze deriveds once their containing effects are destroyed#17921

Draft
Rich-Harris wants to merge 2 commits intomainfrom
inert-deriveds
Draft

fix: freeze deriveds once their containing effects are destroyed#17921
Rich-Harris wants to merge 2 commits intomainfrom
inert-deriveds

Conversation

@Rich-Harris
Copy link
Copy Markdown
Member

Per #17862 (comment), this freezes the value of a derived if it was created inside a parent effect that is now destroyed. This prevents the sort of bug where a derived reads foo.bar even though foo is now undefined.

If the derived is dirty, a warning will be printed.

This PR also gets rid of some weirdness around derived.parent — it can only ever be an Effect | null, and there's no need for get_derived_parent_effect.

Blocked on sveltejs/kit#15533 and a follow-up that switches remote functions to use $effect.root (since this effectively undoes #17171), hence draft.

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 Mar 12, 2026

🦋 Changeset detected

Latest commit: a549d39

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

@github-actions
Copy link
Copy Markdown
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@17921

@svelte-docs-bot
Copy link
Copy Markdown

@Rich-Harris
Copy link
Copy Markdown
Member Author

/autofix

1 similar comment
@Rich-Harris
Copy link
Copy Markdown
Member Author

/autofix

Copy link
Copy Markdown

@codeCraft-Ritik codeCraft-Ritik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice implementation

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.

2 participants