Skip to content

Commit d2efe34

Browse files
committed
fix: Ensure stable unique key in k-items loop
1 parent a037329 commit d2efe34

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

panel/src/components/Collection/Items.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
@change="$emit('change', $event)"
3232
@end="$emit('sort', items, $event)"
3333
>
34-
<template v-for="(item, itemIndex) in items">
34+
<template v-for="(item, itemIndex) in itemsWithIds">
3535
<slot v-bind="{ item, itemIndex }">
3636
<k-item
37-
:key="item.id ?? itemIndex"
37+
:key="item.id"
3838
v-bind="item"
3939
:class="{ 'k-draggable-item': sortable && item.sortable }"
4040
:image="imageOptions(item)"
@@ -143,6 +143,16 @@ export default {
143143
draggable: ".k-draggable-item"
144144
};
145145
},
146+
/**
147+
* Adds a unique id to each item if it doesn't have one
148+
* to be used for `:key` in the `v-for` loop
149+
*/
150+
itemsWithIds() {
151+
return this.items.map((item) => ({
152+
...item,
153+
id: item.id ?? item.uuid ?? this.$helper.uuid()
154+
}));
155+
},
146156
table() {
147157
return {
148158
columns: this.columns,

0 commit comments

Comments
 (0)