Home / Function/ processRootScheduleInMicrotask() — react Function Reference

processRootScheduleInMicrotask() — react Function Reference

Architecture documentation for the processRootScheduleInMicrotask() function in ReactFiberRootScheduler.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  5e2a5e7b_8a85_c79d_5890_361c5a869d24["processRootScheduleInMicrotask()"]
  a22f22c8_f97a_86c8_be5a_4b91a6a21eab["ReactFiberRootScheduler.js"]
  5e2a5e7b_8a85_c79d_5890_361c5a869d24 -->|defined in| a22f22c8_f97a_86c8_be5a_4b91a6a21eab
  e06143aa_b34e_6b03_efeb_9856af499bf6["processRootScheduleInImmediateTask()"]
  e06143aa_b34e_6b03_efeb_9856af499bf6 -->|calls| 5e2a5e7b_8a85_c79d_5890_361c5a869d24
  fb9af2be_1d94_c7da_f1b0_74ad8dd4be7e["scheduleImmediateRootScheduleTask()"]
  fb9af2be_1d94_c7da_f1b0_74ad8dd4be7e -->|calls| 5e2a5e7b_8a85_c79d_5890_361c5a869d24
  2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89["scheduleTaskForRootDuringMicrotask()"]
  5e2a5e7b_8a85_c79d_5890_361c5a869d24 -->|calls| 2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89
  b696b90a_5e97_f015_c2fa_f3bf0b69c0d2["flushSyncWorkAcrossRoots_impl()"]
  5e2a5e7b_8a85_c79d_5890_361c5a869d24 -->|calls| b696b90a_5e97_f015_c2fa_f3bf0b69c0d2
  7562ce78_b7ca_a95a_8338_162d9955da19["startDefaultTransitionIndicatorIfNeeded()"]
  5e2a5e7b_8a85_c79d_5890_361c5a869d24 -->|calls| 7562ce78_b7ca_a95a_8338_162d9955da19
  style 5e2a5e7b_8a85_c79d_5890_361c5a869d24 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberRootScheduler.js lines 259–348

function processRootScheduleInMicrotask() {
  // This function is always called inside a microtask. It should never be
  // called synchronously.
  didScheduleMicrotask = false;
  if (__DEV__) {
    didScheduleMicrotask_act = false;
  }

  // We'll recompute this as we iterate through all the roots and schedule them.
  mightHavePendingSyncWork = false;

  let syncTransitionLanes = NoLanes;
  if (currentEventTransitionLane !== NoLane) {
    if (shouldAttemptEagerTransition()) {
      // A transition was scheduled during an event, but we're going to try to
      // render it synchronously anyway. We do this during a popstate event to
      // preserve the scroll position of the previous page.
      syncTransitionLanes = currentEventTransitionLane;
    } else if (enableDefaultTransitionIndicator) {
      // If we have a Transition scheduled by this event it might be paired
      // with Default lane scheduled loading indicators. To unbatch it from
      // other events later on, flush it early to determine whether it
      // rendered an indicator. This ensures that setState in default priority
      // event doesn't trigger onDefaultTransitionIndicator.
      syncTransitionLanes = DefaultLane;
    }
  }

  const currentTime = now();

  let prev = null;
  let root = firstScheduledRoot;
  while (root !== null) {
    const next = root.next;
    const nextLanes = scheduleTaskForRootDuringMicrotask(root, currentTime);
    if (nextLanes === NoLane) {
      // This root has no more pending work. Remove it from the schedule. To
      // guard against subtle reentrancy bugs, this microtask is the only place
      // we do this — you can add roots to the schedule whenever, but you can
      // only remove them here.

      // Null this out so we know it's been removed from the schedule.
      root.next = null;
      if (prev === null) {
        // This is the new head of the list
        firstScheduledRoot = next;
      } else {
        prev.next = next;
      }
      if (next === null) {
        // This is the new tail of the list
        lastScheduledRoot = prev;
      }
    } else {
      // This root still has work. Keep it in the list.
      prev = root;

      // This is a fast-path optimization to early exit from
      // flushSyncWorkOnAllRoots if we can be certain that there is no remaining
      // synchronous work to perform. Set this to true if there might be sync
      // work left.
      if (
        // Skip the optimization if syncTransitionLanes is set
        syncTransitionLanes !== NoLanes ||
        // Common case: we're not treating any extra lanes as synchronous, so we
        // can just check if the next lanes are sync.
        includesSyncLane(nextLanes) ||
        (enableGestureTransition && isGestureRender(nextLanes))
      ) {
        mightHavePendingSyncWork = true;
      }
    }
    root = next;
  }

  // At the end of the microtask, flush any pending synchronous work. This has
  // to come at the end, because it does actual rendering work that might throw.
  // If we're in the middle of a View Transition async sequence, we don't want to
  // interrupt that sequence. Instead, we'll flush any remaining work when it
  // completes.
  if (!hasPendingCommitEffects()) {

Domain

Subdomains

Frequently Asked Questions

What does processRootScheduleInMicrotask() do?
processRootScheduleInMicrotask() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberRootScheduler.js.
Where is processRootScheduleInMicrotask() defined?
processRootScheduleInMicrotask() is defined in packages/react-reconciler/src/ReactFiberRootScheduler.js at line 259.
What does processRootScheduleInMicrotask() call?
processRootScheduleInMicrotask() calls 3 function(s): flushSyncWorkAcrossRoots_impl, scheduleTaskForRootDuringMicrotask, startDefaultTransitionIndicatorIfNeeded.
What calls processRootScheduleInMicrotask()?
processRootScheduleInMicrotask() is called by 2 function(s): processRootScheduleInImmediateTask, scheduleImmediateRootScheduleTask.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free