Svelte & SvelteKit (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
Svelte 5's Signal Graph: How Push-Pull Reactivity Works Under the Hood.
senior LevelSignalsSystem DesignSvelte 5
In Simple Words: Svelte 5 implements a fine-grained Push-Pull Reactive Graph:
- Push Phase (Dirty Notification): When a
$state()signal changes value, it pushes a notification down the dependency tree marking dependent$derived()signals and$effect()nodes as "dirty". No values are recalculated yet! - Pull Phase (Lazy Evaluation): When the DOM or an effect actually reads the derived signal, it "pulls" the new value, executing calculations only once on-demand.
- If a derived signal computes the exact same value as before, propagation stops immediately, preventing downstream re-renders.