Skip to content

Conversation

Rich-Harris
Copy link
Member

This fixes a tricky bug that occurs with remote functions. I struggled to make a narrow repro, but the change is one that makes sense on the face of it: whenever an async value resolves, we update the batch, flushing the change through the effect tree. This has the effect of destroying anything inside blocks that would otherwise keep them alive.

It feels like we might actually need to go even further than this, and deactivate async work inside skipped branches, but I'm not immediately sure how to tackle that, so just making this change for now.

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

Copy link

changeset-bot bot commented Oct 8, 2025

🦋 Changeset detected

Latest commit: ec721bb

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

Copy link
Contributor

github-actions bot commented Oct 8, 2025

Playground

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

@Rich-Harris
Copy link
Member Author

An example of something that fails without this PR (you can't 'log out'):

@Rich-Harris Rich-Harris merged commit b5c8437 into main Oct 8, 2025
18 checks passed
@Rich-Harris Rich-Harris deleted the flush-eagerly branch October 8, 2025 10:58
@github-actions github-actions bot mentioned this pull request Oct 8, 2025
dummdidumm added a commit that referenced this pull request Oct 8, 2025
Test for #16912

Also some explanation what the bug was:
1. async batch kicks off
2. outer async work succeeds, still something pending, so doesn't do anything for now
3. something unrelated writes to a signal (in the remote functions case it's the query writing to loading, raw etc), which creates a new batch
4. new batch executes. since there are multiple batches it takes the previous value which means if block is still alive. commits that, since no async work from the perspective of this branch
5. inner async work succeeds. now the batch has zero pending async work so it can flush. But the if block is no longer dirty since it was done by the other batch already -> never undos the other work

#16912 fixes it by still traversing the tree which means the if block deletion is scheduled to commit later, which it then does
dummdidumm added a commit that referenced this pull request Oct 8, 2025
Test for #16912

Also some explanation what the bug was:
1. async batch kicks off
2. outer async work succeeds, still something pending, so doesn't do anything for now
3. something unrelated writes to a signal (in the remote functions case it's the query writing to loading, raw etc), which creates a new batch
4. new batch executes. since there are multiple batches it takes the previous value which means if block is still alive. commits that, since no async work from the perspective of this branch
5. inner async work succeeds. now the batch has zero pending async work so it can flush. But the if block is no longer dirty since it was done by the other batch already -> never undos the other work

#16912 fixes it by still traversing the tree which means the if block deletion is scheduled to commit later, which it then does
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.

1 participant