Home / Function/ scheduleImmediateRootScheduleTask() — react Function Reference

scheduleImmediateRootScheduleTask() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  fb9af2be_1d94_c7da_f1b0_74ad8dd4be7e["scheduleImmediateRootScheduleTask()"]
  a22f22c8_f97a_86c8_be5a_4b91a6a21eab["ReactFiberRootScheduler.js"]
  fb9af2be_1d94_c7da_f1b0_74ad8dd4be7e -->|defined in| a22f22c8_f97a_86c8_be5a_4b91a6a21eab
  95634e0b_1432_3e7f_4dd5_05b73a79c629["ensureScheduleIsScheduled()"]
  95634e0b_1432_3e7f_4dd5_05b73a79c629 -->|calls| fb9af2be_1d94_c7da_f1b0_74ad8dd4be7e
  5e2a5e7b_8a85_c79d_5890_361c5a869d24["processRootScheduleInMicrotask()"]
  fb9af2be_1d94_c7da_f1b0_74ad8dd4be7e -->|calls| 5e2a5e7b_8a85_c79d_5890_361c5a869d24
  style fb9af2be_1d94_c7da_f1b0_74ad8dd4be7e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberRootScheduler.js lines 650–695

function scheduleImmediateRootScheduleTask() {
  if (__DEV__ && ReactSharedInternals.actQueue !== null) {
    // Special case: Inside an `act` scope, we push microtasks to the fake `act`
    // callback queue. This is because we currently support calling `act`
    // without awaiting the result. The plan is to deprecate that, and require
    // that you always await the result so that the microtasks have a chance to
    // run. But it hasn't happened yet.
    ReactSharedInternals.actQueue.push(() => {
      processRootScheduleInMicrotask();
      return null;
    });
  }

  // TODO: Can we land supportsMicrotasks? Which environments don't support it?
  // Alternatively, can we move this check to the host config?
  if (supportsMicrotasks) {
    scheduleMicrotask(() => {
      // In Safari, appending an iframe forces microtasks to run.
      // https://github.com/facebook/react/issues/22459
      // We don't support running callbacks in the middle of render
      // or commit so we need to check against that.
      const executionContext = getExecutionContext();
      if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
        // Note that this would still prematurely flush the callbacks
        // if this happens outside render or commit phase (e.g. in an event).

        // Intentionally using a macrotask instead of a microtask here. This is
        // wrong semantically but it prevents an infinite loop. The bug is
        // Safari's, not ours, so we just do our best to not crash even though
        // the behavior isn't completely correct.
        Scheduler_scheduleCallback(
          ImmediateSchedulerPriority,
          processRootScheduleInImmediateTask,
        );
        return;
      }
      processRootScheduleInMicrotask();
    });
  } else {
    // If microtasks are not supported, use Scheduler.
    Scheduler_scheduleCallback(
      ImmediateSchedulerPriority,
      processRootScheduleInImmediateTask,
    );
  }
}

Domain

Subdomains

Frequently Asked Questions

What does scheduleImmediateRootScheduleTask() do?
scheduleImmediateRootScheduleTask() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberRootScheduler.js.
Where is scheduleImmediateRootScheduleTask() defined?
scheduleImmediateRootScheduleTask() is defined in packages/react-reconciler/src/ReactFiberRootScheduler.js at line 650.
What does scheduleImmediateRootScheduleTask() call?
scheduleImmediateRootScheduleTask() calls 1 function(s): processRootScheduleInMicrotask.
What calls scheduleImmediateRootScheduleTask()?
scheduleImmediateRootScheduleTask() is called by 1 function(s): ensureScheduleIsScheduled.

Analyze Your Own Codebase

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

Try Supermodel Free