flush
Edit this pageimport { flush } from "solid-js"
function flush(): voidflush() synchronously applies all pending reactive updates. In Solid 2.0, signal updates are batched by default via microtask scheduling — flush() forces those updates to apply immediately.
When to use
In most cases, you should let the default microtask batching handle updates. Use flush() only when you need to:
- Read DOM measurements immediately after a state change
- Ensure synchronous updates for testing
- Coordinate with external libraries that need immediate DOM state
const [count, setCount] = createSignal(0)
setCount(1)setCount(2)setCount(3)// DOM hasn't updated yet — updates are batched
flush()// Now all pending updates have been applied to the DOMReplacing batch
flush() replaces batch() from Solid 1.x, but with inverted semantics. Where batch wrapped a block of updates to defer them, Solid 2.0 defers by default and flush forces synchronous application:
// 1.x — batch to deferbatch(() => { setA(1) setB(2)})
// 2.0 — deferred by default, flush to force syncsetA(1)setB(2)flush() // only if you need synchronous DOM updatesCaution
Use flush() sparingly. Forcing synchronous updates bypasses the performance benefits of microtask batching. In most applications, the default behavior is sufficient.