queueMicrotask runs before the next paint, setTimeout after it
You can't swap one for the other. A microtask runs as soon as the current task finishes, before the browser paints. setTimeout(fn, 0) runs on the next task, after any pending render.
queueMicrotask(() => flushBatch()); // still this frame
setTimeout(() => measureLayout(), 0); // after layout and paintIf you need the DOM updated first, use the timeout. If you're batching work that has to happen before the user sees anything, use the microtask.
javascript