Performance: Custom transitions
MEDIUM IMPACT
Custom transitions affect the rendering speed and smoothness of animations during element entry and exit, impacting user interaction responsiveness and visual stability.
import { cubicOut } from 'svelte/easing'; function simpleTransition(node, { duration }) { return { duration, css: t => `transform: translateX(${t * 100}px); opacity: ${t}` }; } // Usage: <div transition:simpleTransition={{ duration: 300 }}>Content</div>
import { cubicOut } from 'svelte/easing'; function heavyTransition(node, { duration }) { const start = performance.now(); return { duration, css: t => { // Complex calculation on every frame const progress = Math.sin(t * Math.PI * 10) * 100; return `transform: translateX(${progress}px); opacity: ${t}`; } }; } // Usage: <div transition:heavyTransition={{ duration: 1000 }}>Content</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy math in css function | Minimal (1 element) | Multiple per frame | High (layout-triggering) | [X] Bad |
| Simple transform and opacity | Minimal (1 element) | None | Low (GPU accelerated) | [OK] Good |