Performance: Deferred transitions
MEDIUM IMPACT
Deferred transitions affect the smoothness of animations and the responsiveness of user interactions by postponing heavy transition work until after critical rendering.
<script> import { fade } from 'svelte/transition'; import { tick } from 'svelte'; let visible = false; let showContent = false; async function toggle() { visible = !visible; await tick(); if (visible) { // Defer transition start to next frame requestAnimationFrame(() => showContent = true); } else { showContent = false; } } </script> <button on:click={toggle}>Toggle</button> {#if showContent} <div transition:fade>Content</div> {/if}
<script> import { fade } from 'svelte/transition'; let visible = false; </script> <button on:click={() => visible = !visible}>Toggle</button> {#if visible} <div transition:fade>Content</div> {/if}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Immediate transition start | Multiple DOM updates | Multiple reflows per frame | High paint cost during animation | [X] Bad |
| Deferred transition start | Minimal DOM updates initially | Single reflow before animation | Lower paint cost during animation | [OK] Good |