Stale Closures in Hooks & Callbacks vs Signals and Fine-Grained Reactivity (Reactive Graph)
Signals pass a stable box reference whose .get() always reads the current value without stale closures.
Structured Comparison Matrix
| Dimension | Stale Closures in Hooks & Callbacks | Signals and Fine-Grained Reactivity (Reactive Graph) |
|---|---|---|
| Mental Model | Explains how JavaScript lexical closures snapshot primitive state per render, causing timers, listeners, and suppressed dependency arrays to read outdated values. | Reactive model built on a directed acyclic dependency graph (Signal, Computed, Effect) updating only subscribed DOM nodes without virtual tree diffing. |
| Maturity & Domain | Baseline · Widely · State & Architecture Chrome 1+ (ECMAScript Lexical Scoping) · Firefox 1+ (ECMAScript Lexical Scoping) · Safari 1+ (ECMAScript Lexical Scoping) | Experimental · State & Architecture Chrome TC39 Stage 1 (polyfill) · Firefox TC39 Stage 1 (polyfill) · Safari TC39 Stage 1 (polyfill) |
| Prerequisites | ||
| When Not to Use | When not to use useRef to bypass dependencies: Don't stuff reactive UI state into a ref just to silence a linter, if the effect should re-run when userId changes, keep userId in the dependency array, or move filter/navigation state to URL as State Store. | 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. |
Engine Mechanics & Trade-Offs
Captures immutable primitive values inside a render's lexical closure; async callbacks or omitted dependency arrays read outdated snapshots unless bridged via refs or functional updaters.
Key Pitfalls: Silencing react-hooks/exhaustive-deps: Adding // eslint-disable-next-line to force an effect to run once is the fastest way to ship stale auth tokens or outdated filters in WebSocket handlers. Debounced callbacks capturing old props: Creating a debounced save() inside render without memoizing or reading a ref sends yes
Glitch-free push-pull propagation over an acyclic observer graph.
Key Pitfalls: Effects writing to tracked signals (infinite loop): An effect mutating 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.
Seen in Architecture Autopsies
SPA operations dashboard climbs from 120 MB to 2.4 GB RAM over an 8-hour shift and crashes with Aw, Snap!
Changing a single URL filter triggers an infinite render loop, Maximum update depth exceeded, and a burst of 429 Too Many Requests responses.