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/perf-props-stability-update-optimization.md
1---2title: Keep Props Stable to Minimize Child Re-renders3impact: HIGH4impactDescription: Passing changing props to list items causes ALL children to re-render unnecessarily5type: efficiency6tags: [vue3, performance, props, v-for, re-renders, optimization]7---89# Keep Props Stable to Minimize Child Re-renders1011**Impact: HIGH** - When props passed to child components change, Vue must re-render those components. Passing derived values like `activeId` to every list item causes all items to re-render when activeId changes, even if only one item's active state actually changed.1213Move comparison logic to the parent and pass the boolean result instead. This is one of the most impactful update performance optimizations in Vue.1415## Task Checklist1617- [ ] Avoid passing parent-level state that all children compare against (like `activeId`)18- [ ] Pre-compute derived boolean props in the parent (like `:active="item.id === activeId"`)19- [ ] Profile re-renders using Vue DevTools to identify prop stability issues20- [ ] Consider this pattern especially critical for large lists2122**Incorrect:**23```vue24<template>25<!-- BAD: activeId changes -> ALL 100 ListItems re-render -->26<ListItem27v-for="item in list"28:key="item.id"29:id="item.id"30:active-id="activeId"31/>32</template>3334<script setup>35import { ref } from 'vue'3637const list = ref([/* 100 items */])38const activeId = ref(null)3940// When activeId changes from 1 to 2:41// - ListItem 1 needs to re-render (was active, now not)42// - ListItem 2 needs to re-render (was not active, now active)43// - All other 98 ListItems ALSO re-render because activeId prop changed!44</script>45```4647```vue48<!-- ListItem.vue - receives activeId and compares internally -->49<template>50<div :class="{ active: id === activeId }">51{{ id }}52</div>53</template>5455<script setup>56defineProps({57id: Number,58activeId: Number // This prop changes for ALL items59})60</script>61```6263**Correct:**64```vue65<template>66<!-- GOOD: Only items whose :active actually changed will re-render -->67<ListItem68v-for="item in list"69:key="item.id"70:id="item.id"71:active="item.id === activeId"72/>73</template>7475<script setup>76import { ref } from 'vue'7778const list = ref([/* 100 items */])79const activeId = ref(null)8081// When activeId changes from 1 to 2:82// - ListItem 1: :active changed from true to false -> re-renders83// - ListItem 2: :active changed from false to true -> re-renders84// - All other 98 ListItems: :active is still false -> NO re-render!85</script>86```8788```vue89<!-- ListItem.vue - receives pre-computed boolean -->90<template>91<div :class="{ active }">92{{ id }}93</div>94</template>9596<script setup>97defineProps({98id: Number,99active: Boolean // This only changes for items that truly changed100})101</script>102```103104## Common Patterns That Cause Prop Instability105106```vue107<!-- BAD: Passing index that could shift -->108<Item109v-for="(item, index) in items"110:key="item.id"111:index="index"112:total="items.length" <!-- Changes when list changes -->113/>114115<!-- BAD: Passing entire selection set -->116<Item117v-for="item in items"118:key="item.id"119:selected-ids="selectedIds" <!-- All items re-render on any selection -->120/>121122<!-- GOOD: Pre-compute the boolean -->123<Item124v-for="item in items"125:key="item.id"126:selected="selectedIds.includes(item.id)"127/>128```129130## Performance Impact Example131132| Scenario | Props Changed | Components Re-rendered |133|----------|---------------|------------------------|134| 100 items, pass `activeId` | 100 | 100 (all) |135| 100 items, pass `:active` boolean | 2 | 2 (only changed) |136| 1000 items, pass `activeId` | 1000 | 1000 (all) |137| 1000 items, pass `:active` boolean | 2 | 2 (only changed) |138139## Reference140- [Vue.js Performance - Props Stability](https://vuejs.org/guide/best-practices/performance.html#props-stability)141