Skip to content

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

Merged
Rich-Harris merged 13 commits into
sveltejs:mainfrom
apoorvdarshan:fix/select-stale-value-on-dynamic-options
Mar 13, 2026
Merged

Rich-Harris merged 13 commits into
sveltejs:mainfrom
apoorvdarshan:fix/select-stale-value-on-dynamic-options

Conversation

@apoorvdarshan

Copy link
Copy Markdown
Contributor

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

changeset-bot Bot commented Feb 18, 2026 •

Copy link
Copy Markdown

πŸ¦‹ Changeset detected

Latest commit: 91bcab9

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
Copy Markdown

@apoorvdarshan

Copy link
Copy Markdown
Contributor Author

Added changeset in 176c63b.

Comment thread .changeset/fix-select-stale-value.md Resolved

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@Rich-Harris
Rich-Harris merged commit 3dbd950 into sveltejs:main Mar 13, 2026
17 checks passed
@github-actions github-actions Bot mentioned this pull request Mar 13, 2026
Rich-Harris pushed a commit that referenced this pull request Mar 14, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## svelte@5.53.12

### Patch Changes

- fix: update `select.__value` on `change`
([#17745](#17745))

- chore: add `invariant` helper for debugging
([#17929](#17929))

- fix: ensure deriveds values are correct across batches
([#17917](#17917))

- fix: handle async RHS in `assignment_value_stale`
([#17925](#17925))

- fix: avoid traversing clean roots
([#17928](#17928))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
dlrobson added a commit to dlrobson/dlrobson.github.io that referenced this pull request Mar 22, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [svelte](https://svelte.dev) ([source](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte)) | [`5.53.7` β†’ `5.54.1`](https://renovatebot.com/diffs/npm/svelte/5.53.7/5.54.1) | ![age](https://developer.mend.io/api/mc/badges/age/npm/svelte/5.54.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/svelte/5.53.7/5.54.1?slim=true) |
| [svelte](https://svelte.dev) ([source](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte)) | [`5.53.6` β†’ `5.54.1`](https://renovatebot.com/diffs/npm/svelte/5.53.6/5.54.1) | ![age](https://developer.mend.io/api/mc/badges/age/npm/svelte/5.54.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/svelte/5.53.6/5.54.1?slim=true) |

---

### Release Notes

<details>
<summary>sveltejs/svelte (svelte)</summary>

### [`v5.54.1`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5541)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.54.0...svelte@5.54.1)

##### Patch Changes

- fix: hydration comments during hmr ([#&#8203;17975](sveltejs/svelte#17975))

- fix: null out `effect.b` in `destroy_effect` ([#&#8203;17980](sveltejs/svelte#17980))

- fix: group sync statements ([#&#8203;17977](sveltejs/svelte#17977))

- fix: defer batch resolution until earlier intersecting batches have committed ([#&#8203;17162](sveltejs/svelte#17162))

- fix: properly invoke `iterator.return()` during reactivity loss check ([#&#8203;17966](sveltejs/svelte#17966))

- fix: remove trailing semicolon from {[@&#8203;const](https://github.com/const)} tag printer ([#&#8203;17962](sveltejs/svelte#17962))

### [`v5.54.0`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5540)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.53.13...svelte@5.54.0)

##### Minor Changes

- feat: allow `css`, `runes`, `customElement` compiler options to be functions ([#&#8203;17951](sveltejs/svelte#17951))

##### Patch Changes

- fix: reinstate reactivity loss tracking ([#&#8203;17801](sveltejs/svelte#17801))

### [`v5.53.13`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#55313)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.53.12...svelte@5.53.13)

##### Patch Changes

- fix: ensure `$inspect` after top level await doesn't break builds ([#&#8203;17943](sveltejs/svelte#17943))

- fix: resume inert effects when they come from offscreen ([#&#8203;17942](sveltejs/svelte#17942))

- fix: don't eagerly access not-yet-initialized functions in template ([#&#8203;17938](sveltejs/svelte#17938))

- fix: discard batches made obsolete by commit ([#&#8203;17934](sveltejs/svelte#17934))

- fix: ensure "is standalone child" is correctly reset ([#&#8203;17944](sveltejs/svelte#17944))

- fix: remove nodes in boundary when work is pending and HMR is active ([#&#8203;17932](sveltejs/svelte#17932))

### [`v5.53.12`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#55312)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.53.11...svelte@5.53.12)

##### Patch Changes

- fix: update `select.__value` on `change` ([#&#8203;17745](sveltejs/svelte#17745))

- chore: add `invariant` helper for debugging ([#&#8203;17929](sveltejs/svelte#17929))

- fix: ensure deriveds values are correct across batches ([#&#8203;17917](sveltejs/svelte#17917))

- fix: handle async RHS in `assignment_value_stale` ([#&#8203;17925](sveltejs/svelte#17925))

- fix: avoid traversing clean roots ([#&#8203;17928](sveltejs/svelte#17928))

### [`v5.53.11`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#55311)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.53.10...svelte@5.53.11)

##### Patch Changes

- fix: remove `untrack` circular dependency ([#&#8203;17910](sveltejs/svelte#17910))

- fix: recover from errors that leave a corrupted effect tree ([#&#8203;17888](sveltejs/svelte#17888))

- fix: properly lazily evaluate RHS when checking for `assignment_value_stale` ([#&#8203;17906](sveltejs/svelte#17906))

- fix: resolve boundary in correct batch when hydrating ([#&#8203;17914](sveltejs/svelte#17914))

- chore: rebase batches after process, not during ([#&#8203;17900](sveltejs/svelte#17900))

### [`v5.53.10`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#55310)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.53.9...svelte@5.53.10)

##### Patch Changes

- fix: re-process batch if new root effects were scheduled ([#&#8203;17895](sveltejs/svelte#17895))

### [`v5.53.9`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5539)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.53.8...svelte@5.53.9)

##### Patch Changes

- fix: better `bind:this` cleanup timing ([#&#8203;17885](sveltejs/svelte#17885))

### [`v5.53.8`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5538)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.53.7...svelte@5.53.8)

##### Patch Changes

- fix: `{@&#8203;html}` no longer duplicates content inside `contenteditable` elements ([#&#8203;17853](sveltejs/svelte#17853))

- fix: don't access inert block effects ([#&#8203;17882](sveltejs/svelte#17882))

- fix: handle asnyc updates within pending boundary ([#&#8203;17873](sveltejs/svelte#17873))

- perf: avoid re-traversing the effect tree after `$:` assignments ([#&#8203;17848](sveltejs/svelte#17848))

- chore: simplify scheduling logic ([#&#8203;17805](sveltejs/svelte#17805))

</details>

---

### Configuration

πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

πŸ”• **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My44NC4yIiwidXBkYXRlZEluVmVyIjoiNDMuODQuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://forgejo.tail5a98.ts.net/gooilers123/monolith/pulls/47
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

3 participants