[]previous and next page

Order of execution

Order of execution in the Effects and lifecycle guide.

For agentsUpdated

On every flush the engine drains two queues. The following order governs the work in each flush.

  1. Render effects (useRenderEffect, compiler bindings) run before user effects (useEffect, onMount).
  2. Within a phase, effects run shallower owner first, then by creation order. A parent effect runs before the effects created inside child roots.
  3. When an effect re-runs, its children are disposed first, then its cleanups run (newest first), then the body runs again.
  4. 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.
  5. Effects created during a flush run in a following pass of that flush.
  6. After 1000 passes the flush is aborted and a ShadowError with code INFINITE_LOOP is thrown (to the caller of flushSync/batch, or reported when the flush was scheduled in a microtask).
  7. A disposed effect never runs, even if it was already queued.
  8. User effects and onMount created below a Suspense boundary that has a pending first load are held until it resolves for the first time. Render effects are never held (see Suspense and resources).