How each keyed block works #18028
Replies: 1 comment 2 replies
-
|
This is edge case is caused by component "instance" being reused when the array is mutated. So the icon, which is assigned to a On the other hand, the "text" (in the docs example "name") is defined as a What the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, thanks for the amazing works.
I try to understand how the keyed each block works under the hood by reading the doc
My understanding so far when there is no key given and causing the bug in the example of the doc:
When we remove the first’s item in the array, Svelte removes the last DOM node, then updates the remaining nodes.
Here is what I’m confused about, why only the text got updated but not the icon/src?
Apparently if Svelte did some comparisons for the src, it is the not the same.
As we removed the last item, I understand that the index remains the same and thus Svelte might thought nothing changes, but in this case, doesn’t the text also be the same make more sense?
I try to understand how it works instead of just following the doc where adding the key will definitely solved the problem.
Beta Was this translation helpful? Give feedback.
All reactions