--- title: TransitionGroup Children Must Have Unique Keys impact: HIGH impactDescription: Missing or non-unique keys cause broken animations and Vue warnings type: gotcha tags: [vue3, transition-group, animation, key, v-for, list-animation] --- # TransitionGroup Children Must Have Unique Keys **Impact: HIGH** - Unlike regular ``, the `` component **always requires** a unique `key` attribute on every child element. Without keys, Vue cannot track individual items, animations will break, and you'll see console warnings. This is a fundamental difference from `` which works on single elements. Since `` animates lists of elements, Vue needs keys to track which items are entering, leaving, or moving. ## Task Checklist - [ ] Ensure every direct child of `` has a unique `key` attribute - [ ] Use stable identifiers (IDs) rather than array indices for keys - [ ] Do not use the same key for different items at different times - [ ] When using `v-for`, always include `:key` binding **Incorrect - Missing keys:** ```vue ``` **Incorrect - Using index as key:** ```vue ``` When using index as key: - If you remove item at index 2, what was index 3 becomes index 2 - Vue thinks index 2 changed content rather than being removed - Animations fire on wrong elements **Correct - Unique stable keys:** ```vue ``` **Correct - Keys on static children:** ```vue ``` ## Common Error Messages Without keys, you'll see warnings like: ``` [Vue warn]: children must be keyed. ``` ## With Draggable Libraries When using `` with libraries like `vue.draggable.next`, key issues can cause errors: ```javascript // Error you might see without proper keys TypeError: domElement is null ``` Ensure all draggable items have unique keys: ```vue ``` ## Reference - [Vue.js TransitionGroup](https://vuejs.org/guide/built-ins/transition-group.html) - [Vue.js List Rendering Keys](https://vuejs.org/guide/essentials/list.html#maintaining-state-with-key)