Performance: svelte:self for recursive components
MEDIUM IMPACT
This affects rendering performance by controlling how recursive components render and update in the browser.
<script> export let node; </script> <div> {node.name} {#each node.children as child} <svelte:self node={child} /> {/each} </div>
<script> export let node; </script> <div> {node.name} {#each node.children as child} <Component node={child} /> {/each} </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using component name recursively | Many nested components created | Multiple reflows per recursive level | High paint cost due to many updates | [X] Bad |
| Using svelte:self for recursion | Reuses component instance | Single reflow per update cycle | Lower paint cost with efficient updates | [OK] Good |