Skip to content

fix: prevent flushed effects from running again#17787

Merged
dummdidumm merged 1 commit intomainfrom
effect-clear-fix
Feb 25, 2026
Merged

fix: prevent flushed effects from running again#17787
dummdidumm merged 1 commit intomainfrom
effect-clear-fix

Conversation

@dummdidumm
Copy link
Member

We never cleared the list of (maybe)dirty_effects on the assumption that once a batch has run them it's complete. But that's not the case when a boundary has a pending snippet, in which case the pending snippet shows up, so blocking_pending is already 0 and effects are flushed. That can lead to effects being run unnecessarily, even leading to infinite loops.

So we clear them. This is safe because any additional effects would either be scheduled by the boundary (which keeps track of the offscreen effects created while the pending snippet is shown, and schedules them once the pending snippet goes away) or by unskipping skipped branches (which reschedules the effects inside it)

Fixes #17717

After creating the test I noticed it fails when run together with other tests, but not alone, which lead me to discover that we're missing an unset_context. I also added clearing of #skipped_branches just to be safe.

We never cleared the list of (maybe)dirty_effects on the assumption that once a batch has run them it's complete. But that's not the case when a boundary has a pending snippet, in which case the pending snippet shows up, so `blocking_pending` is already 0 and effects are flushed. That can lead to effects being run unnecessarily, even leading to infinite loops.

So we clear them. This is safe because any additional effects would either be scheduled by the boundary (which keeps track of the offscreen effects created while the pending snippet is shown, and schedules them once the pending snippet goes away) or by unskipping skipped branches (which reschedules the effects inside it)

Fixes #17717

After creating the test I noticed it fails when run together with other tests, but not alone, which lead me to discover that we're missing an `unset_context`. I also added clearing of `#skipped_branches` just to be safe.
@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2026

🦋 Changeset detected

Latest commit: 61fcb6b

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
Contributor

Playground

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

@phi-bre
Copy link

phi-bre commented Feb 24, 2026

Thank you for working on this issue! I gave this PR a spin to see if this finally fixes the infinite loops, but almost immediately ran into a different issue:

Navigating with goto from one subpage with an ID slug to another (e.g. /bananas/123 to /apples/456) updates the old page with the new parameter before actually navigating (so bananas/456), which causes an error due to apples not being bananas, so old page shows error boundary before any navigation happens.

(for context, the browser shows the correct new url, not the bananas/456)

Feels more like a regression of this PR than a follow up issue as far as I can tell

@dummdidumm
Copy link
Member Author

dummdidumm commented Feb 24, 2026

Please provide a reproduction. Are you maybe running into sveltejs/kit#15395 ?

@phi-bre
Copy link

phi-bre commented Feb 24, 2026

I'm working on a reproduction, but I have yet to actually achieve the same behaviour... so maybe it is something in user-land after all.

If I do manage to create a reproduction, I'll open a new issue 👍

Its unlikely to be related to sveltejs/kit#15395, as I don't have SSR enabled in my app, but it I'll double check if its related to sveltejs/kit#14996

@dummdidumm dummdidumm merged commit 1b3e660 into main Feb 25, 2026
20 checks passed
@dummdidumm dummdidumm deleted the effect-clear-fix branch February 25, 2026 16:02
@github-actions github-actions bot mentioned this pull request Feb 25, 2026
elliott-with-the-longest-name-on-github pushed a commit that referenced this pull request Feb 25, 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
## svelte@5.53.4

### Patch Changes

- fix: set server context after async transformError
([#17799](#17799))

- fix: hydrate if blocks correctly
([#17784](#17784))

- fix: handle default parameters scope leaks
([#17788](#17788))

- fix: prevent flushed effects from running again
([#17787](#17787))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@phi-bre
Copy link

phi-bre commented Feb 26, 2026

@dummdidumm I actually managed to reproduce the bug: sveltejs/kit#15431

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.

Problem with subsequent await calls.

3 participants