Performance: Deferred transitions
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 |
deferred transitions in Svelte?transition:fade={{ deferred: true }}.show variable changes from false to true?
{#if show}
Welcome!
{/if}
deferred: true option with delay: 200 waits for page stability before delaying the fade by 200ms.fade transition runs after stability and delay, causing a smooth fade-in.
{#if visible}
Content
{/if}
transition:deferred:fade is not valid in Svelte.{#each} block?{{ deferred: true }} inside a transition like fade to delay until stable.transition:fade={{ deferred: true }} on each li correctly defers fade per item.Pass the test and this pattern moves unknown