Performance: If blocks ({#if})
MEDIUM IMPACT
Controls conditional rendering which impacts DOM size and layout recalculations during state changes.
{#if showContent}
<div>Content</div>
{/if} <!-- element only in DOM when needed --><div style="display: none">Content</div> <!-- always in DOM but hidden -->
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using CSS display:none to hide elements | No DOM changes | No reflow triggered for hidden elements | Paint triggered for hidden elements | [X] Bad |
| Using {#if} to conditionally render elements | DOM nodes added/removed as needed | Single reflow per toggle | Paint only for visible elements | [OK] Good |