Skip to content

fix: unset batch before flushing queued effects #16482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jul 23, 2025
Merged

fix: unset batch before flushing queued effects #16482

merged 21 commits into from
Jul 23, 2025

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Jul 22, 2025

I wish I could claim credit for this but it's all @dummdidumm, I'm just opening a PR to make working on it easier. Essentially, we now create a fresh batch to handle any state changes that occur during effects that run after the prior batch is committed

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

dummdidumm and others added 9 commits July 22, 2025 17:50
Copy link
Contributor

Playground

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

Copy link

changeset-bot bot commented Jul 22, 2025

🦋 Changeset detected

Latest commit: 82e431f

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
Member Author

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

can't approve because it's 'my' PR but this LGTM. there are definitely adjacent things that could likely be finessed, but given how many issues this fixes I think we should merge it

@@ -202,9 +203,22 @@ export class Batch {
this.#effects = [];
this.#block_effects = [];

// If sources are written to, then work needs to happen in a separate batch, else prior sources would be mixed with
// newly updated sources, which could lead to infinite loops when effects run over and over again.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we've been hunting infinite loop problem in our code in 5.35.5 I am wondering if this comment means that there were indeed a possibility that svelte creates them? That'd be a relief to know

Copy link
Member

Choose a reason for hiding this comment

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

It should only happen in case of async though

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly! Will be interested to see if this version fixes things

Copy link
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.

Great simplifications!

@Rich-Harris Rich-Harris merged commit 8e2f4b5 into main Jul 23, 2025
15 checks passed
@Rich-Harris Rich-Harris deleted the async-fixes branch July 23, 2025 11:55
@github-actions github-actions bot mentioned this pull request Jul 23, 2025
@paoloricciuti
Copy link
Member

Did anybody said already that @dummdidumm is the GOAT? 🐐

@Rich-Harris
Copy link
Member Author

multiple times a day 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy