-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Get rid of each_item_invalid_assignment in svelte 5 #13592
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
Comments
The passed collection can be not-an-array, so you cannot just do |
That seems like a good reason for it to be pretty hard (if not impossible) to implement. Thanks for taking the time! |
Hello, I think that is not a sufficient reason :
Personally I think the each_item_invalid_assignment compile-error should be removed, and replaced by a runtime-error when the collection is not an array. |
It works in non-runes mode because the invalidation is not fine-grained. The whole array gets invalidated. |
I just find this restriction strange : if And actually I just tested it simply by commenting out the each_item_invalid_assignment error... and it's just work. $.bind_value(input, () => arr[$$index], ($$value) => (arr[$$index] = $$value)); I must be missing something... or it is an arbitrary constraint. |
Of course, it will "work" - you can add props to any object unless it is frozen or custom setters reject writing. However, the iterator is still unaware of these new props and will return the old values.
|
In case of bind/assignment, instead of throwing each_item_invalid_assignment, the compiler could just pass a flag to => So if I use that with a non-array, I will get a runtime-error... |
I think I found the reason by Rich Harris:
So, in cases like Edit: It was initially forbidden because there was no proxy state; thus, it was impossible. Later, after introducing the proxy state, they decided to keep it for the reason above. |
Yes this reason is more understandable. |
Describe the problem
When converting a component from svelte 4 to svelte 5 (runes mode), I noticed the each_item_invalid_assignment error. The error message says "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)". That means it is no longer possible to write
Instead, I now have to write
Describe the proposed solution
For me, it seems like it would be fairly straight forward to just let the compiler replace
value
withvalues[i]
. That way, the code would be a little cleaner to write and would stay compatible with the svelte 4 way, while at the same time satisfy the underlying constraint that makes this necessary.Importance
nice to have
The text was updated successfully, but these errors were encountered: