Skip to content

Svelte 5: select bindings broken when options rendered via #each loop #9412

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

Closed
theodorejb opened this issue Nov 13, 2023 · 0 comments · Fixed by #9471
Closed

Svelte 5: select bindings broken when options rendered via #each loop #9412

theodorejb opened this issue Nov 13, 2023 · 0 comments · Fixed by #9471
Milestone

Comments

@theodorejb
Copy link
Contributor

theodorejb commented Nov 13, 2023

Describe the bug

When a select element value binding doesn't match an option, no option should be selected. This works correctly in Svelte 4 and is tested in tests/runtime-legacy/samples/binding-select-unmatched. However, it is broken in Svelte 5 when the option elements are rendered from an array via an #each loop (rather than hardcoded like they are in the test). The first option incorrectly appears selected, even though its value doesn't match the select element value binding.

Secondly, when a select element value binding is initially undefined, then the first non-disabled or selected option value should be selected (and the bound variable set to its value). This also works in Svelte 4, and is tested via tests/runtime-legacy/samples/binding-select-initial-value-undefined and tests/runtime-legacy/samples/binding-select-initial-value-undefined-2. However, this is likewise broken in Svelte 5 when the options are rendered via an #each loop. The expected option appears selected, but the variable bound to the select value fails to be initialized with the selected option value.

Reproduction

binding-select-unmatched broken when options rendered in each loop.

binding-select-initial-value-undefined broken when options rendered in each loop.

Logs

No response

System Info

Firefox, Chromium, Edge

Severity

blocking an upgrade

@dummdidumm dummdidumm added this to the 5.x milestone Nov 13, 2023
@theodorejb theodorejb changed the title Svelte 5: select bindings broken when options rendered via each loop Svelte 5: select bindings broken when options rendered via #each loop Nov 14, 2023
dummdidumm added a commit that referenced this issue Nov 15, 2023
when options are added later, we need to ensure the select value still stays in sync
fixes #9412
trueadm pushed a commit that referenced this issue Nov 15, 2023
when options are added later, we need to ensure the select value still stays in sync
fixes #9412
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 a pull request may close this issue.

2 participants