Skip to content

fix: set and flushSync state that should render in if when another state is set breaks reactivity temporarily #16077

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

raythurnvoid
Copy link
Contributor

@raythurnvoid raythurnvoid commented Jun 4, 2025

In this PR i'm restoring the flushSync optimization introduced in #15855 that was replaced by #15895.

I reverted #15895 and adapted #15855 to the more recent changes of flushSync

In particular the problem seems to be that setting is_flushing to true before calling flush_tasks
prevents the reactivity to work normally when a state is update in a flushSync and that same value is used in an if block that should be rendered after setting another state right after the flushSync.

Here are relevant playgrounds:

Before the regression
https://svelte.dev/playground/a89aaf76146c4571a996d7cd02e39d2f?version=5.28.2

When the regression was introduced
https://svelte.dev/playground/a89aaf76146c4571a996d7cd02e39d2f?version=5.28.3

Actual version, still broken
https://svelte.dev/playground/a89aaf76146c4571a996d7cd02e39d2f?version=5.33.14

Unfortunately I failed to reproduce the issue in the jsdom env, however it can be clearly tested both with sv create and in the playground.

Do you plan to upgrade vitest and switch to browser mode in the future?

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

raythurnvoid and others added 5 commits June 4, 2025 01:17
…ltejs#15895)

* chore: avoid microtasks when flushing sync

* chore: avoid microtasks when flushing sync

* chore: avoid microtasks when flushing sync

* tweak

* WIP

* another

* more

* tweak

* fix

* fix

* belt and braces

* Revert "belt and braces"

This reverts commit f8de1cf.

---------

Co-authored-by: Dominic Gannaway <[email protected]>"

This reverts commit b616412.
# Conflicts:
#	packages/svelte/src/internal/client/runtime.js
Copy link

changeset-bot bot commented Jun 4, 2025

🦋 Changeset detected

Latest commit: 9c0a31f

The changes in this PR will be included in the next version bump.

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 Jun 4, 2025

Playground

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

@raythurnvoid raythurnvoid changed the title Fix/@sveltejs/svelte/#16076 fix: set and flushSync state that should render in if when another state is set breaks reactivity Jun 4, 2025
@raythurnvoid raythurnvoid changed the title fix: set and flushSync state that should render in if when another state is set breaks reactivity fix: set and flushSync state that should render in if when another state is set breaks reactivity temporarily Jun 4, 2025
@raythurnvoid
Copy link
Contributor Author

This fixes #16076

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.

2 participants