fix: run blocks eagerly during flush
#16631
Pull request
Another stab at #16548. The idea is that if a block effect is dirtied by a state change in another effect, it jumps to the head of the queue rather than waiting for the next root-to-tip traversal. That way, if it ends up destroying its children, they get destroyed immediately, rather than running even though they're about to be destroyed (which can result in errors — #16072).
Because we're not causing extra traversals, this (as far as I've been able to determine) fully removes the performance overhead introduced by #16280, without regressing on correctness. It also fixes the false positive infinite loop detection.
The one part I really don't love is the old_values.clear() — it gets the tests passing (one fails without it) but feels wrong. I stole it from #16612 — maybe @dummdidumm can explain if/why/how it's okay.
It also seems weird that we need to schedule the block effects in addition to running them eagerly, but if we don't then one test fails. Will investigate when my brain isn't running on fumes.
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:, ordocs:. - 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 testand lint the project withpnpm lint
Info
🦋 Changeset detected
Latest commit: 5d6b081
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
pnpm add https://pkg.pr.new/svelte@16631fix: only abort effect flushing if it causes an existing effect to be scheduled
• Aug 14, 2025, 6:28 PM