Vue · VUE0040
Pass list items a computed comparison
Finds v-for children that receive the same parent value on every item and compare it with one of their own per-item props.
vue/perf/prefer-stable-list-propssrc/rule-packs/vue/rules/vue/prefer-stable-list-props.ts Upstream docs Run this rule
pnpm vite-doctor . --framework vue --extends auto,vue/strict --rules vue/perf/prefer-stable-list-props
Why it matters
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
Recommended fix
Compare in the parent and pass the result as a boolean prop, such as
Useful links
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>