Closed leolorenzoluis closed 2 years ago
This is probably due to how Lit does the diffing when removing/adding elements from a list. Apparently it's much faster to remove the last child instead of one in the middle. So what Lit does is, instead of deleting from the middle of the list, it removes the actual HTML element and the end and reuses the other elements. This is why the hook gets confused and applies the class to what should be a different element.
To avoid this, when rendering a dynamic list, it's recommended to use mapUnique
to give a unique ID to each item. This will allow Lit to correctly identify each item and avoid situations like this: https://github.com/fable-compiler/Fable.Lit/blob/6317d3a32ed91927984b1fc03aa7da3fc02affa3/src/Lit/Lit.fs#L265-L272
Lit expects a string as its identifier?
Yes, this is common in JS (React also expects the key prop to be a string). Keys must be unique and shouldn't change between renders (e.g. don't use the index if you're going to sort the list or remove/add elements in the middle).
With Fable a usual pattern is to add a Guid property to the items and then convert it to string when passing to Lit or React.
So I implemented it and it almost is identical to the animations that you have for TodoMVC. However, when I try to delete an item from the list say in the middle, then the next item will add
transition-enter
on the next sibling. It looks like transition-enter is getting applied to the next item aftertransition.triggerLeave
is called?Given the following code:
When the delete button is clicked, the next sibling is left hanging with transition-enter. I expect no transition class name is left hanging. I've checked the
update
function that I have and the delete is only getting called once.Update: I changed
model.Monitors |> Seq.map
toLit.mapUnique
and it works perfectly fine. Documentation refer to the method asNot sure what
included item transition
means here and why would it fix it? Also, why does mapUnique expects theId
to be a string?