fix: keep select.__value current when effect is deferred#17745
Open
apoorvdarshan wants to merge 2 commits intosveltejs:mainfrom
Open
fix: keep select.__value current when effect is deferred#17745apoorvdarshan wants to merge 2 commits intosveltejs:mainfrom
apoorvdarshan wants to merge 2 commits intosveltejs:mainfrom
Conversation
) When a <select> is focused inside an async boundary, the bind_select_value effect gets deferred, leaving select.__value stale. If options then change dynamically (e.g. via {#each}), the MutationObserver in init_select uses the stale __value, snapping the select to the wrong option. Update __value in the change handler and in the effect's early-return path so the MutationObserver always has the correct value.
🦋 Changeset detectedLatest commit: 176c63b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Author
|
Added changeset in 176c63b. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #17148
When a
<select>is focused inside an async boundary, thebind_select_valueeffect gets deferred by the batch system, leavingselect.__valuestale. If options then change dynamically (e.g. via{#each}), theMutationObserverininit_selectuses the stale__value, snapping the select to the wrong option.__valuein the change handler so it's always current, even when the effect is deferred__valuein the effect's early-return path (defensive fix for when the effect runs but skips the DOM update)Test plan
select-dynamic-options-while-focusedtest that renders a<select>with dynamic{#each}options inside an async boundary, selects a non-initial option while focused, adds another option, and verifies the select retains the user's choiceasync-binding-update-while-focused-3test still passespnpm test)