Order of execution
Order of execution in the Effects and lifecycle guide.
On every flush the engine drains two queues. The following order governs the work in each flush.
- Render effects (
useRenderEffect, compiler bindings) run before user effects (useEffect,onMount). - Within a phase, effects run shallower owner first, then by creation order. A parent effect runs before the effects created inside child roots.
- When an effect re-runs, its children are disposed first, then its cleanups run (newest first), then the body runs again.
- An effect that writes a signal re-queues its readers. They run in a following pass of the same flush, so a flush ends only when nothing is pending.
- Effects created during a flush run in a following pass of that flush.
- After 1000 passes the flush is aborted and a
ShadowErrorwith codeINFINITE_LOOPis thrown (to the caller offlushSync/batch, or reported when the flush was scheduled in a microtask). - A disposed effect never runs, even if it was already queued.
- User effects and
onMountcreated below aSuspenseboundary that has a pending first load are held until it resolves for the first time. Render effects are never held (see Suspense and resources).