Closed
Description
Describe the bug
Consider the following:
<script>
const options = [
{text: "Text 1"},
{text: "Text 2"},
{text: "Text 3"},
]
let selected = $state(options[0])
</script>
<select bind:value={selected}>
{#each options as option}
<option value={option}>{option.text}</option>
{/each}
</select>
The select element will not correctly display options[0]
as being selected. This is likely due to an identity-check being used against a Proxy
in Svelte internals.
To workaround this, wrap the options
array in a $state
rune. Using $state.frozen
will not work.
I'm not sure if this is intended behaviour. If so, perhaps we should document this edge case with the workaround.
Reproduction
Logs
No response
System Info
System:
OS: macOS 14.4.1
CPU: (12) arm64 Apple M3 Pro
Memory: 152.89 MB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 21.6.1 - /opt/homebrew/bin/node
npm: 10.4.0 - /opt/homebrew/bin/npm
pnpm: 8.15.1 - /opt/homebrew/bin/pnpm
bun: 1.0.26 - ~/.bun/bin/bun
Browsers:
Chrome: 124.0.6367.91
Safari: 17.4.1
npmPackages:
svelte: 5.0.0-next.118 => 5.0.0-next.118
Severity
annoyance
Metadata
Metadata
Assignees
Labels
No labels