Skip to content
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

Svelte 5: <select> options with object references. #11403

Closed
TheCymaera opened this issue Apr 30, 2024 · 1 comment · Fixed by #11613
Closed

Svelte 5: <select> options with object references. #11403

TheCymaera opened this issue Apr 30, 2024 · 1 comment · Fixed by #11613
Assignees
Milestone

Comments

@TheCymaera
Copy link
Contributor

TheCymaera commented Apr 30, 2024

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

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE21Ou2rEMBD8lWWTIgET59EJ2ZB_SGe5UOQ9ItBJwlofF4z-PchSrkm6eezszI4n6yihmHb0-kwo8D1G7JC_YyHpQo4JO0xhW01RZDKrjTwqb4JPDCGyDT7BAJPyinemKwtQ-EFXhheFufsrv_4vv1V5Vl55RwyJHBmmBQa4T6yZHlrZ9Dw_Ki_72xRZT-HT-kVctNto2H_TeTya7kibr9tanRrMxVQsK4OWbd7YwFOZmWVfWf3Xl3_5WHEUjdjhOSz2ZGlBwetGec4_GI8Ytl8BAAA=

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

@Rich-Harris Rich-Harris added this to the 5.0 milestone Apr 30, 2024
@dm-de
Copy link

dm-de commented May 1, 2024

I'm not sure - this is possible similar issue:
#10120

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.

4 participants