Performance: Keyed each blocks
HIGH IMPACT
This affects how efficiently the browser updates the DOM when lists change, impacting rendering speed and visual stability.
<script> let items = [1, 2, 3]; </script> {#each items as item (item)} <div>{item}</div> {/each}
<script> let items = [1, 2, 3]; </script> {#each items as item} <div>{item}</div> {/each}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unkeyed each block | Recreates or reorders many DOM nodes | Multiple reflows per update | High paint cost due to layout shifts | [X] Bad |
| Keyed each block | Updates only changed DOM nodes | Single or minimal reflows | Low paint cost with stable layout | [OK] Good |