-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Self-assignments of each contexts don't trigger proper reactivity #3217
Comments
That is a tricky one in my opinion. Equality of values vs. equality of references can lead to subtle issues down the road. By tracking the content of the array for changes, you would end up having to track recursively those contents (imagine the array contains arrays, or other objects). If you do that for arrays, you logically have to do it for objects too (because arrays are objects or else you have to explain why one and not the other) etc. Then you have the case when the current behaviour is actually the desired behaviour (e.g. don't track inner changes) so you would have to deal with that use case with maybe extra syntax, and that's more complexity yet again. In short. there is plenty of complexity hidden there and a ton of bugs. I actually think it is simpler to say to educate around/document reference equality. Here how how |
Comment from my dupe: Describe the bug To clarify, it seems that assignments to an To Reproduce On removing the curly braces, Svelte will correctly invalidate the array. Expected behaviour Severity There are workarounds, it isn't the worst thing that has ever happened in the world. |
This looks like it was also fixed by #3533. |
Clicking the items here does not cause them to toggle:
I believe this should work. There also seem to be a few other permutation that aren't working (having
mutate
return theitem
, and then having the click handler doitem = mutate(item);
. I thought that reassigning to an{#each}
context that can be traced back to a top-level variable would also invalidate that top-level variable - and it seems like it does, in certain cases - but I'm not entirely sure that the intended behavior is here. It might be simplest if we just said 'no, only assignments to top-level variables triggers re-rendering', but that's probably not ideal.The text was updated successfully, but these errors were encountered: