docs / Runtime
Scheduler
When writes actually reach the DOM: flushSync, tick, and what batches for you.
Writes are batched. Several cell writes in one turn become one update pass, so a render is never half-applied. That is almost always invisible — and occasionally not, which is what these two are for.
| Call | Does |
|---|---|
| flushSync() | Applies every pending write immediately and synchronously. Returns once the DOM is up to date. |
| tick() | Yields to the microtask queue so pending updates land, without forcing a synchronous flush mid-expression. |
component Probe() {
const &[n] = track(0)
// Two writes, then read the DOM: without flushSync the element still shows 0.
const probe = () => {
n++
n++
flushSync()
const el = document.querySelector('#probe')
console.log(el ? el.textContent : 'not on the server')
}
<span id="probe">{n}</span>
<button onClick={probe}>run</button>
}
Do not reach for flushSync by reflex. It forces a synchronous DOM pass, which costs a layout flush and can hide ordering bugs. Reach for it when you genuinely must observe the DOM right after a write — measuring, focusing, or driving an imperative API.
On the server there is no scheduler to flush: SSR renders once, in order, and flushSync() is a no-op. The example above still renders — it simply logs nothing, because document does not exist.