Vue · performance
vite-doctor/vueperformanceinfoNo fix
Why it happens
A Vue child component re-renders when any prop it receives changes. When every item of a v-for gets the same parent value, such as
Fix
Compare in the parent and pass the result as a boolean prop, such as
Example
Pass the comparison result to list items
Before
<!-- ListItem.vue -->
<script setup lang="ts">
const props = defineProps<{ id: number; activeId: number | null }>()
const active = computed(() => props.id === props.activeId)
</script>
<!-- List.vue -->
<template>
<ListItem v-for="item in list" :key="item.id" :id="item.id" :active-id="activeId" />
</template>
After
<!-- ListItem.vue -->
<script setup lang="ts">
defineProps<{ id: number; active: boolean }>()
</script>
<!-- List.vue -->
<template>
<ListItem v-for="item in list" :key="item.id" :id="item.id" :active="item.id === activeId" />
</template>
Verify the fix
Run only this rule after editing so the report stays focused on the diagnostic you are closing:
pnpm vite-doctor . --framework vue --extends auto,vue/strict --rules vue/perf/prefer-stable-list-props