Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vue 3 debugging reference for reactivity issues, computed errors, watcher bugs, async failures, and SSR hydration problems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/transition-group-no-default-wrapper-vue3.md
1---2title: TransitionGroup No Longer Renders Default Wrapper Element in Vue 33impact: MEDIUM4impactDescription: Vue 2 to Vue 3 migration may break layouts relying on the default span wrapper5type: gotcha6tags: [vue3, transition-group, migration, vue2, breaking-change, wrapper-element]7---89# TransitionGroup No Longer Renders Default Wrapper Element in Vue 31011**Impact: MEDIUM** - In Vue 2, `<transition-group>` always rendered a wrapper element (default `<span>`), but in Vue 3, it renders no wrapper element by default thanks to fragment support. This breaking change can cause layout issues and broken styles when migrating from Vue 2.1213If your code relies on the wrapper element for styling or layout, you must explicitly specify the `tag` prop in Vue 3.1415## Task Checklist1617- [ ] When migrating from Vue 2, add explicit `tag` prop to all `<TransitionGroup>` components18- [ ] Review CSS selectors that targeted the wrapper element19- [ ] Update parent component styles that expected a wrapper element20- [ ] Consider if the wrapper element is actually needed in Vue 32122**Vue 2 Behavior (wrapper element by default):**23```vue24<template>25<transition-group name="list">26<div v-for="item in items" :key="item.id">{{ item }}</div>27</transition-group>28</template>2930<!-- Renders as: -->31<span> <!-- Default wrapper in Vue 2 -->32<div>Item 1</div>33<div>Item 2</div>34</span>35```3637**Vue 3 Behavior (no wrapper by default):**38```vue39<template>40<TransitionGroup name="list">41<div v-for="item in items" :key="item.id">{{ item }}</div>42</TransitionGroup>43</template>4445<!-- Renders as (fragment): -->46<div>Item 1</div>47<div>Item 2</div>48<!-- No wrapper element! -->49```5051**Vue 3 - Explicitly specify wrapper:**52```vue53<template>54<!-- Use tag prop to specify wrapper element -->55<TransitionGroup name="list" tag="ul">56<li v-for="item in items" :key="item.id">{{ item }}</li>57</TransitionGroup>58</template>5960<!-- Renders as: -->61<ul>62<li>Item 1</li>63<li>Item 2</li>64</ul>65```6667## Migration Scenarios6869### Layout Depending on Wrapper7071**Vue 2 code that breaks in Vue 3:**72```vue73<template>74<transition-group class="grid-container" name="list">75<div v-for="item in items" :key="item.id">{{ item }}</div>76</transition-group>77</template>7879<style>80.grid-container {81display: grid;82grid-template-columns: repeat(3, 1fr);83}84</style>85```8687In Vue 3, the class is not applied to anything because there's no wrapper element.8889**Fixed for Vue 3:**90```vue91<template>92<TransitionGroup class="grid-container" name="list" tag="div">93<div v-for="item in items" :key="item.id">{{ item }}</div>94</TransitionGroup>95</template>96```9798### Semantic HTML Lists99100**Vue 2:**101```vue102<transition-group tag="ul" name="list">103<li v-for="item in items" :key="item.id">{{ item }}</li>104</transition-group>105```106107**Vue 3 (same syntax, but now tag is more important):**108```vue109<TransitionGroup tag="ul" name="list">110<li v-for="item in items" :key="item.id">{{ item }}</li>111</TransitionGroup>112```113114### When You Don't Need a Wrapper115116Vue 3's fragment support means you might not need a wrapper at all:117118```vue119<template>120<div class="parent-with-styles">121<!-- No tag needed if parent handles layout -->122<TransitionGroup name="fade">123<span v-for="item in items" :key="item.id">{{ item }}</span>124</TransitionGroup>125</div>126</template>127128<style>129.parent-with-styles {130display: flex;131gap: 8px;132}133</style>134```135136## In-DOM Template Syntax137138When using in-DOM templates (not SFCs), remember to use kebab-case:139140```html141<!-- In-DOM template -->142<transition-group tag="ul" name="list">143<li v-for="item in items" :key="item.id">{{ item }}</li>144</transition-group>145146<!-- NOT -->147<TransitionGroup tag="ul" name="list"> <!-- Won't work in DOM templates -->148```149150## Reference151- [Vue 3 Migration Guide - TransitionGroup Root Element](https://v3-migration.vuejs.org/breaking-changes/transition-group.html)152- [Vue.js TransitionGroup](https://vuejs.org/guide/built-ins/transition-group.html)153