Batching and Glitch-Free Updates
You'll learn how modern signal systems prevent "glitches"—those awkward moments when derived values briefly show inconsistent intermediate states during cascading updates.
The Glitch Problem
Imagine a signal system where firstName and lastName are signals, and fullName is computed from them. If you update both names in sequence without batching, fullName might recompute after each change:
firstName = "Alice", lastName = "Smith" → fullName = "Alice Smith"
firstName = "Bob" → fullName = "Bob Smith" (GLITCH!)
lastName = "Jones" → fullName = "Bob Jones" (correct)
That middle state—"Bob Smith"—is a glitch: a momentarily inconsistent derived value that should never have been visible.
How Batching Solves This
Batching means collecting multiple signal updates into a single transaction, then propagating changes once at the end. The signal system:
- Marks signals as "dirty" during updates
- Delays recomputation of dependent computed signals
- Flushes all changes together in a topologically-sorted order
- Ensures each computed signal runs exactly once per batch
Think of it like updating a spreadsheet: you don't want formulas recalculating after every keystroke—you want all edits to settle first, then recalculate everything efficiently in one pass.
Why It Matters
Glitch-free updates guarantee consistency: UI never displays impossible states, and effects never fire with stale data. Modern signal libraries (like SolidJS or Vue's reactivity) batch updates automatically, often synchronously within the same JavaScript task, or by deferring to microtasks.
Without batching, you'd need manual transaction control or risk triggering dozens of unnecessary recomputations and side effects.
Key Takeaway:
Batching collects signal updates into atomic transactions, preventing glitches by ensuring computed values and effects only react once to a consistent set of changes.