Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: freeze effects-inside-deriveds when disconnecting, unfreeze on reconnect#17682

Merged
Rich-Harris merged 6 commits into
mainfrom
freeze-derived-effects
Feb 12, 2026
Merged

fix: freeze effects-inside-deriveds when disconnecting, unfreeze on reconnect#17682
Rich-Harris merged 6 commits into
mainfrom
freeze-derived-effects

Conversation

@Rich-Harris
Copy link
Copy Markdown
Member

@Rich-Harris Rich-Harris commented Feb 11, 2026

This supersedes #16595, and fixes the issue by 'freezing' effects inside deriveds when those deriveds are disconnected, and unfreezing them when they reconnect. This is preferable to the current asymmetric behaviour on main (in which effects are destroyed when the derived is disconnected, and never recreated) and #16595, which causes the derived itself to be re-evaluated.

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 Feb 11, 2026

🦋 Changeset detected

Latest commit: bfa7cc4

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

@svelte-docs-bot
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

Playground

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

…nside a derived that doesn't probably create more work than it saves
@Rich-Harris Rich-Harris temporarily deployed to Publish pkg.pr.new (maintainers) February 12, 2026 00:37 — with GitHub Actions Inactive
@Rich-Harris Rich-Harris marked this pull request as ready for review February 12, 2026 00:37
Copy link
Copy Markdown
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

This works and is a good solution, but it adds more code and I'm wondering if we should instead opt for an overall "simpler" model. I believe the main reason people run into connect/disconnect is because they create global state outside of a reactive context. So what if we allow to create deriveds/effects outside of a reactive context, and if so we warn about it and just never clean it up? This likely makes the whole connect/disconnect much simpler, and we can instead rerun deriveds when they reconnect - which is much rarer in this world.

Anyway that's all food for thought and shouldn't hold up this PR, because the current behavior definitely is more broken.

@Rich-Harris
Copy link
Copy Markdown
Member Author

Ownership (whether or not a derived was created inside an effect tree) and connection (whether or not anything currently depends on the derived) aren't the same thing though.

Anyway, I just realised we don't handle abort signals in this PR, and in the process of fixing that realised that we're currently over-running effects for some reason... investigating

@Rich-Harris Rich-Harris temporarily deployed to Publish pkg.pr.new (maintainers) February 12, 2026 14:04 — with GitHub Actions Inactive
@Rich-Harris Rich-Harris merged commit 4eee2f7 into main Feb 12, 2026
21 checks passed
@Rich-Harris Rich-Harris deleted the freeze-derived-effects branch February 12, 2026 14:15
@github-actions github-actions Bot mentioned this pull request Feb 12, 2026
Rich-Harris pushed a commit that referenced this pull request Feb 12, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## [email protected]

### Patch Changes

- fix: take into account `nodeName` case sensitivity on XHTML pages
([#17689](#17689))

- fix: render `multiple` and `selected` attributes as empty strings for
XHTML compliance
([#17689](#17689))

- fix: always lowercase HTML elements, for XHTML compliance
([#17664](#17664))

- fix: freeze effects-inside-deriveds when disconnecting, unfreeze on
reconnect ([#17682](#17682))

- fix: propagate `$effect` errors to `<svelte:boundary>`
([#17684](#17684))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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