show warning when using x-for without :key #4623
slaide
started this conversation in
3. Feature Ideas
Replies: 1 comment 2 replies
-
|
Without :key the index is used by default. The "odd side effects" is related to how, if you remove an item in the middle of the list, instead of removing that element (and any nested components) corresponding with that item from the dom, it will instead remove the last element, and change the ones between that item and the end to refer to new items, which may maintain incorrect nested state. It might also be totally fine for a lot of cases. Maybe it should include a warning, not totally sure. Too many warnings is its own issue in bloating package size... |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
the x-for docs say that
It is important to specify unique keys for each x-for iteration if you are going to be re-ordering items. Without dynamic keys, Alpine may have a hard time keeping track of what re-orders and will cause odd side-effects..I believe that behaviour that may cause
odd side-effects(tracking that down just took me over an hour, hence this request) should not be the default, or at least not without a notice of some kind. #1639 to me indicates that improper:keyusage should at least entail a warning, andwill cause odd side-effectsseems high stakes enough.(Also, that note only mentions changing the order of the list, not changing the contents of the list as a more general statement, which seems like weird wording.)
Beta Was this translation helpful? Give feedback.
All reactions