Performance: Named slots and scoped slots
MEDIUM IMPACT
This concept affects rendering performance by controlling how much DOM is created and how often components re-render due to slot content changes.
<ChildComponent> <template #default="{ data }"> <div>{{ data }}</div> </template> </ChildComponent>
<ChildComponent>
<template #default>
<div>{{ expensiveComputation() }}</div>
</template>
</ChildComponent>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline dynamic slot content | High (many nodes updated) | Multiple reflows per update | High paint cost due to frequent changes | [X] Bad |
| Scoped slots with precomputed props | Low (minimal updates) | Single reflow per update | Low paint cost due to fewer changes | [OK] Good |
| Named slots with inline static content | Medium (recreated each render) | Some reflows due to patching | Medium paint cost | [!] OK |
| Named slots with static child components | Low (cached nodes) | Minimal reflows | Low paint cost | [OK] Good |