Skip to content

Comments

fix: keep select.__value current when effect is deferred#17745

Open
apoorvdarshan wants to merge 2 commits intosveltejs:mainfrom
apoorvdarshan:fix/select-stale-value-on-dynamic-options
Open

fix: keep select.__value current when effect is deferred#17745
apoorvdarshan wants to merge 2 commits intosveltejs:mainfrom
apoorvdarshan:fix/select-stale-value-on-dynamic-options

Conversation

@apoorvdarshan
Copy link

Summary

Fixes #17148

When a <select> is focused inside an async boundary, the bind_select_value effect gets deferred by the batch system, 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 so it's always current, even when the effect is deferred
  • Update __value in the effect's early-return path (defensive fix for when the effect runs but skips the DOM update)

Test plan

  • Added select-dynamic-options-while-focused test 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 choice
  • Verified existing async-binding-update-while-focused-3 test still passes
  • All 7151 tests pass (pnpm test)

)

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

changeset-bot bot commented Feb 18, 2026

🦋 Changeset detected

Latest commit: 176c63b

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

@svelte-docs-bot
Copy link

@apoorvdarshan
Copy link
Author

Added changeset in 176c63b.

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.

<select> displays wrong choice when options are dynamically updated

1 participant