onremove and key change #2725
Replies: 8 comments
-
It's a common gotcha, and it took me a while to detect it as well... Keys only work in list context. Wrap the The tricky thing is that the engine implicitly creates lists in some places but not always. |
Beta Was this translation helpful? Give feedback.
-
The route docs advocate using |
Beta Was this translation helpful? Give feedback.
-
@barneycarroll |
Beta Was this translation helpful? Give feedback.
-
@pygy the expected behaviour is intuitive, and describing the reasons for the edge case is awkward and unrewarding. How about we change components to always wrap returns in fragments? This would fix the issue transparently and make vnode structure more predictable. |
Beta Was this translation helpful? Give feedback.
-
@cavemansspa in the meantime, it's easy enough to ensure all element & component nodes are in lists by wrapping view return values in arrays: https://jsfiddle.net/barney/Lsr7be0y/ |
Beta Was this translation helpful? Give feedback.
-
Here's another instance of this: https://jsfiddle.net/u9rgLyk2/3/ My intention for using Another solution would be a new lifecycle method |
Beta Was this translation helpful? Give feedback.
-
@valtron -- did you see the gitter followups https://gitter.im/mithriljs/mithril.js?at=5c3125053cf6c35a8497fd6d and https://gitter.im/mithriljs/mithril.js?at=5c31280e1491b27876c818ff? |
Beta Was this translation helpful? Give feedback.
-
@cavemansspa I did, that's just a workaround though, required by the fact that mixing keyed/unkeyed nodes isn't supported/defined. Would be better, IMO, to define and support this behaviour, since the change is so simple. |
Beta Was this translation helpful? Give feedback.
-
Should
onremove
be invoked in this example: https://jsfiddle.net/6dysnpkL/Beta Was this translation helpful? Give feedback.
All reactions