fix: run blocks eagerly during flush

#16631

Pull request

Merged
R
Rich-Harris
Aug 16, 2025, 1:23 AM

Another stab at . 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 — ).

Because we're not causing extra traversals, this (as far as I've been able to determine) fully removes the performance overhead introduced by , 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 — 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:, 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

Info

Merged at Aug 17, 2025, 12:31 PM
Merged by dummdidumm
Assignees None
Reviewers None
Labels None
Milestone None