Performance: svelte:component for dynamic components
MEDIUM IMPACT
This affects rendering speed and responsiveness by dynamically switching components at runtime.
<script> import ComponentA from './ComponentA.svelte'; import ComponentB from './ComponentB.svelte'; let showA = true; </script> {#if showA} <ComponentA /> {:else} <ComponentB /> {/if}
<svelte:component this={component} /> <script> let component = ComponentA; // component changes frequently on user input </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Dynamic svelte:component with frequent changes | High (destroy + create nodes) | Multiple reflows per change | High paint cost due to full component redraw | [X] Bad |
| Conditional rendering with {#if} blocks | Low (only toggles visibility) | Single reflow per toggle | Lower paint cost, partial updates | [OK] Good |