fix: set and flushSync state that should render in if when another state is set breaks reactivity temporarily #16077
+86
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
totrue
before callingflush_tasks
prevents the reactivity to work normally when a state is update in a
flushSync
and that same value is used in anif block
that should be rendered after setting anotherstate
right after theflushSync
.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
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint