Skip to content

fix: keep input in sync when binding updated via effect #16464

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

Closed
wants to merge 1 commit into from

Conversation

dummdidumm
Copy link
Member

Fixes #16413

The previous fix was insufficient as it didn't account for effects running as a result of a change, which is executed in a different batch. Instead we now set a boolean that is true while an async branch is flushed.

Also added a test for the expected async behavior where inputs should not update, AFAICT that didn't exist before.

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

Fixes #16413

The previous fix was insufficient as it didn't account for effects running as a result of a change, which is executed in a different batch. Instead we now set a boolean that is true while an async branch is flushed.
Copy link

changeset-bot bot commented Jul 21, 2025

🦋 Changeset detected

Latest commit: bf7de3a

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

Playground

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

@gyzerok
Copy link
Contributor

gyzerok commented Jul 21, 2025

@dummdidumm we've got also hit by this in prod. Mind making a new release when this gets merged?

@Rich-Harris
Copy link
Member

Note that the test case behaves differently if you change <p>{value}</p> to <p>{await value}</p>. That feels like a weird inconsistency; perhaps we need to find a different heuristic?

Rich-Harris added a commit that referenced this pull request Jul 22, 2025
Rich-Harris added a commit that referenced this pull request Jul 23, 2025
* - add state changes resulting from an $effect to a separate new batch
- schedule rerunning effects based on the sources that are dirty, not just rerunning them all blindly (excempting async effects which will have run by that time already)

* test

* better fix

* tests

* this fixes the last test somehow

* fix #16477

* typo

* copy over changeset from #16477

* copy over changeset from #16464

* changeset

* dedupe

* move flushing_sync check inside Batch.ensure

* unused

* flushing_sync -> is_flushing_sync

* remove flush_effects method

* dedupe declaration

* tweak

* tweak

* update comment — it _does_ feel slightly wrong, but no wronger than the rest of this cursed function

---------

Co-authored-by: Simon Holthausen <[email protected]>
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.

input bind doesn't work as expected since 5.36.0
3 participants