Without setting the key, there will be a strange delay in the update of x-for. #4240
Replies: 2 comments 1 reply
-
it must be a bug to do with Alpine not thinking the user has changed (no key means that you use the array index as a key. because you are not even modifying the array but reassigning it in toto, Alpine thing that the item in pos 0 at the second rendering is the same as the item in pos 0 at the first rendering). In general, why are using Alpine in a non canonical way (Manually calling |
Beta Was this translation helpful? Give feedback.
-
So it's kind of two things. Not having a key makes change tracking much harder. The second is Alpine trying to prevent circular updates, so if something needs to be recalculated multiple times, it won't allow itself to run the effect more than once in a cycle. changing host causes the first one to rerender while it still has the original user, since the keys and such didn't change. When layer the x-for tries to give it the new user, it has already updated so won't do so again. But mostly, x-for should never be used without a The update on the first line is always one behind, due to the effect schedular not allowing the effect to be requeued. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this is a bug, but I'll post it here to help others who come after me.
I wrote a reproducible webpage example, but the code is a bit long, so I put it at the end.
Visit this webpage ( JSFiddle ) and click the switch button.
The first click will output:
Everything is normal.
But when you click the button again, it will output:
The data of the first
x-for
does not seem to be updated correctly.example:
Beta Was this translation helpful? Give feedback.
All reactions