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/animation-transitiongroup-performance.md
1---2title: TransitionGroup Performance with Large Lists and CSS Frameworks3impact: MEDIUM4impactDescription: TransitionGroup can cause noticeable DOM update lag when animating list changes, especially with CSS frameworks5type: gotcha6tags: [vue3, transition-group, animation, performance, list, css-framework]7---89# TransitionGroup Performance with Large Lists and CSS Frameworks1011**Impact: MEDIUM** - Vue's `<TransitionGroup>` can experience significant DOM update lag when animating list changes, particularly when:12- Using CSS frameworks (Tailwind, Bootstrap, etc.)13- Performing array operations like `slice()` that change multiple items14- Working with larger lists1516Without TransitionGroup, DOM updates occur instantly. With it, there can be noticeable delay before the UI reflects changes.1718## Task Checklist1920- [ ] For frequently updated lists, consider if transition animations are necessary21- [ ] Use CSS `content-visibility: auto` for long lists to reduce render cost22- [ ] Minimize CSS framework classes on list items during transitions23- [ ] Consider virtual scrolling for very large animated lists24- [ ] Profile with Vue DevTools to identify transition bottlenecks2526**Problematic Pattern:**27```vue28<template>29<!-- Potentially slow with large lists or complex CSS -->30<TransitionGroup name="list" tag="ul">31<li32v-for="item in items"33:key="item.id"34class="p-4 m-2 rounded-lg shadow-md bg-gradient-to-r from-blue-500 to-purple-60035hover:shadow-lg transition-all duration-300 ease-in-out transform hover:scale-10536border border-gray-200 flex items-center justify-between"37>38{{ item.name }}39</li>40</TransitionGroup>41</template>4243<script setup>44import { ref } from 'vue'4546const items = ref([/* many items */])4748// Operations like slice can cause visible lag49function removeItems() {50items.value = items.value.slice(5) // May lag with TransitionGroup51}52</script>5354<style>55.list-move,56.list-enter-active,57.list-leave-active {58transition: all 0.5s ease;59}60</style>61```6263**Optimized Approach:**64```vue65<template>66<!-- Simpler classes, shorter transitions -->67<TransitionGroup name="list" tag="ul" class="relative">68<li69v-for="item in items"70:key="item.id"71class="list-item"72>73{{ item.name }}74</li>75</TransitionGroup>76</template>7778<script setup>79import { ref, computed } from 'vue'8081const items = ref([/* items */])8283// For large batch operations, consider disabling animations temporarily84const isAnimating = ref(true)85</script>8687<style>88/* Keep transition CSS simple and specific */89.list-item {90/* Minimal styles during animation */91padding: 1rem;92}9394.list-move {95transition: transform 0.3s ease; /* Shorter duration */96}9798.list-enter-active,99.list-leave-active {100transition: opacity 0.2s ease, transform 0.2s ease;101}102103.list-enter-from,104.list-leave-to {105opacity: 0;106transform: translateX(-20px);107}108109/* Use will-change sparingly */110.list-enter-active {111will-change: opacity, transform;112}113114/* Absolute positioning for leaving elements prevents layout thrashing */115.list-leave-active {116position: absolute;117width: 100%;118}119</style>120```121122## Performance Optimization Strategies123124### 1. Skip Animations for Bulk Operations125126```vue127<template>128<TransitionGroup v-if="animationsEnabled" name="list" tag="ul">129<li v-for="item in items" :key="item.id">{{ item.name }}</li>130</TransitionGroup>131132<!-- Instant update without animations -->133<ul v-else>134<li v-for="item in items" :key="item.id">{{ item.name }}</li>135</ul>136</template>137138<script setup>139import { ref, nextTick } from 'vue'140141const animationsEnabled = ref(true)142143async function bulkUpdate(newItems) {144// Disable animations for bulk operations145animationsEnabled.value = false146items.value = newItems147await nextTick()148animationsEnabled.value = true149}150</script>151```152153### 2. Virtual Scrolling for Large Lists154155```vue156<template>157<!-- Use a virtual list library for large datasets -->158<RecycleScroller159:items="items"160:item-size="50"161key-field="id"162v-slot="{ item }"163>164<div class="list-item">{{ item.name }}</div>165</RecycleScroller>166</template>167168<script setup>169import { RecycleScroller } from 'vue-virtual-scroller'170</script>171```172173### 3. Reduce CSS Complexity During Transitions174175```vue176<style>177/* Move complex styles to a stable wrapper */178.list-item-wrapper {179@apply p-4 m-2 rounded-lg shadow-md bg-gradient-to-r from-blue-500 to-purple-600;180}181182/* Keep animated element styles minimal */183.list-item {184/* Only essential layout styles */185}186187.list-move,188.list-enter-active,189.list-leave-active {190/* Only animate transform/opacity - GPU accelerated */191transition: transform 0.3s ease, opacity 0.3s ease;192}193</style>194```195196### 4. Use CSS content-visibility197198```css199/* For very long lists, defer rendering of off-screen items */200.list-item {201content-visibility: auto;202contain-intrinsic-size: 0 50px; /* Estimated height */203}204```205206## When to Avoid TransitionGroup207208Consider alternatives when:209- List updates are frequent (real-time data)210- List contains 100+ items211- Items have complex CSS or nested components212- Performance is critical (mobile, low-end devices)213214```vue215<!-- Simple alternative: CSS-only animations on individual items -->216<ul>217<li218v-for="item in items"219:key="item.id"220class="animate-in"221>222{{ item.name }}223</li>224</ul>225226<style>227@keyframes fadeIn {228from { opacity: 0; transform: translateY(-10px); }229to { opacity: 1; transform: translateY(0); }230}231232.animate-in {233animation: fadeIn 0.3s ease forwards;234}235</style>236```237238## Reference239- [Vue.js TransitionGroup](https://vuejs.org/guide/built-ins/transition-group.html)240- [GitHub Issue: transition-group DOM update lag](https://github.com/vuejs/vue/issues/5845)241- [Vue Virtual Scroller](https://github.com/Akryum/vue-virtual-scroller)242