Performance: onMount
MEDIUM IMPACT
onMount affects the timing of when JavaScript code runs after the component is added to the page, impacting initial interaction readiness and rendering speed.
import { onMount } from 'svelte'; onMount(() => { setTimeout(() => { // heavy code deferred for (let i = 0; i < 100000000; i++) {} }, 0); });
import { onMount } from 'svelte'; onMount(() => { // heavy synchronous code for (let i = 0; i < 100000000; i++) {} });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous code in onMount | 1 (component mount) | 1 reflow triggered | Blocks paint until done | [X] Bad |
| Light or deferred code in onMount | 1 (component mount) | 1 reflow triggered | Paint happens promptly | [OK] Good |