Performance: Dynamic render patterns
MEDIUM IMPACT
This affects how quickly the page updates and how smoothly user interactions feel when Vue dynamically renders or updates components.
<template>
<div>
<component
v-for="item in items"
:is="item.type"
:key="item.id"
/>
</div>
</template>
<script setup>
import { ref } from 'vue'
const items = ref([...])
// stable keys ensure Vue efficiently patches only changed items
</script><template>
<div>
<component v-for="item in items" :is="item.type" />
</div>
</template>
<script setup>
import { ref } from 'vue'
const items = ref([...])
// items update frequently causing all components to re-render
</script>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Dynamic components without stable key | Many nodes updated | N reflows per update | High paint cost | [X] Bad |
| Dynamic components with stable key | Only changed nodes updated | Minimal reflows | Lower paint cost | [OK] Good |