Signals and Fine-Grained Reactivity (Reactive Graph)
A Signal wraps an observable value that automatically tracks reads inside a computed or effect. Writes propagate updates only to the exact nodes reading that value, in O(1) relative to DOM size.
State Propagation: VDOM Diff vs Signals
function Parent() {
const [count, setCount] = useState(0);
return <ExpensiveTree count={count} />;
}Requires memo/useCallback to prevent cascading re-renders.
const count = new Signal.State(0);
const doubled = new Signal.Computed(() => count.get() * 2);
// Only the subscribed text node updatesZero virtual tree diffing on each mutation.
doubled = 0Under the Hood
- Automatic Tracking: When a
computedoreffectruns, it pushes its context onto a global tracking stack; eachsignal.get()adds asignal -> observeredge. - Push-Pull Propagation: Calling
signal.set(v)marks descendantsDirty(Push) without eagerly recomputing lazy derived values, avoiding wasted V8 Hidden Classes allocations on unused branches. - Lazy Evaluation (Pull): A
computedonly recomputes when read, and short-circuits downstream effects (often flushed on the Event Loop microtask checkpoint) if its new value equals the previous one.
const count = signal(1);
const doubled = computed(() => count.get() * 2);
effect(() => {
// Re-runs ONLY when `doubled` actually changes
badgeEl.textContent = String(doubled.get());
});Problem Genealogy
- 2010 (KnockoutJS Observables): Early reactive graph with auto-tracking, but without glitch-free guarantees.
- 2013 (React Virtual DOM): Full subtree re-rendering plus diff reconciliation to simplify the mental model, trading CPU cycles for a
useEffectdependency array that everyone eventually misconfigures. - 2024+ (TC39 Signals Proposal): Standardizing a glitch-free reactive primitive shared across frameworks.
Production Pitfalls
- Effects writing to tracked signals (infinite loop): An
effectmutating a signal it reads re-triggers the graph indefinitely until stack overflow. - Losing reactivity via destructuring: Extracting
const v = signal.get()outside the tracked execution scope breaks dynamic subscription.
- When not to use Signals: For simple forms or mostly static pages, native DOM primitives avoid unnecessary abstraction overhead; for multi-step workflows with illegal state combinations, pair or replace raw signals with Finite State Machines.
Connections & Logical Next Steps
Both proxy stores and compiled reactivity build fine-grained dependency edges between state and DOM.
Reactive effect batching commonly relies on a microtask flush.
Signals propagate arbitrary reactive value changes, whereas finite state machines enforce explicit transition guards.
Signals pass a stable box reference whose .get() always reads the current value without stale closures.
VDOM diffs whole component subtrees on state changes; Signals update subscribed DOM nodes in O(1).
Mechanical Comparisons
Signals propagate arbitrary reactive value changes, whereas finite state machines enforce explicit transition guards.
Signals pass a stable box reference whose .get() always reads the current value without stale closures.
VDOM diffs whole component subtrees on state changes; Signals update subscribed DOM nodes in O(1).