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

Runes mode: Binding in each loop not working #14702

Open
ralphdelfs opened this issue Dec 13, 2024 · 1 comment
Open

Runes mode: Binding in each loop not working #14702

ralphdelfs opened this issue Dec 13, 2024 · 1 comment

Comments

@ralphdelfs
Copy link

Describe the bug

In runes mode, when iterating an array of objects in an each loop, it is not possible to bind the object to a component.

<svelte:options runes={true} />
<script>
	import Component from "./Component.svelte"
	
	let objs = [{
		val: "foo"
	}]
</script>

{#each objs as obj}
  <Component bind:obj />
{/each}

Error each_item_invalid_assignment is raised. This works fine when runes mode is disabled.

Reproduction

https://svelte.dev/playground/71e6da2a2afd4a5e812bdd7263e5c7dd?version=5.12.0

Logs

Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. `array[i] = value` instead of `entry = value`)
https://svelte.dev/e/each_item_invalid_assignment

System Info

svelte 5.12.0, see repl

Severity

blocking an upgrade

@Prinzhorn
Copy link
Contributor

Prinzhorn commented Dec 13, 2024

This comes up regularly, maybe the error message should be better? the error message tells you exactly what to do.

Use the array and index variables instead (e.g. array[i] = value instead of entry = value)

You need to use the index: https://svelte.dev/playground/3d2230fb0247489dafb27f995901b1a6?version=5.12.0

Edit: still, the error message is a little poorly worded and does not look like a binding, it should be:

(e.g. bind:value={array[i] instead of bind:value={entry})

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