scheduleTaskForRootDuringMicrotask() — react Function Reference
Architecture documentation for the scheduleTaskForRootDuringMicrotask() function in ReactFiberRootScheduler.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89["scheduleTaskForRootDuringMicrotask()"] a22f22c8_f97a_86c8_be5a_4b91a6a21eab["ReactFiberRootScheduler.js"] 2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89 -->|defined in| a22f22c8_f97a_86c8_be5a_4b91a6a21eab 5e2a5e7b_8a85_c79d_5890_361c5a869d24["processRootScheduleInMicrotask()"] 5e2a5e7b_8a85_c79d_5890_361c5a869d24 -->|calls| 2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89 1c7960af_fcd5_d6c9_ece2_ba8ee42ad12c["performWorkOnRootViaSchedulerTask()"] 1c7960af_fcd5_d6c9_ece2_ba8ee42ad12c -->|calls| 2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89 37d023ee_52cb_df7b_96a7_ab4d3938d19c["cancelCallback()"] 2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89 -->|calls| 37d023ee_52cb_df7b_96a7_ab4d3938d19c 11e67036_9b86_244a_fe14_483ba27b0376["lanesToEventPriority()"] 2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89 -->|calls| 11e67036_9b86_244a_fe14_483ba27b0376 1beb843d_0f9e_46a6_110d_6fdec691be24["scheduleCallback()"] 2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89 -->|calls| 1beb843d_0f9e_46a6_110d_6fdec691be24 style 2f0b078e_5ecb_a4c3_220a_f89cb5bd5a89 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-reconciler/src/ReactFiberRootScheduler.js lines 384–509
function scheduleTaskForRootDuringMicrotask(
root: FiberRoot,
currentTime: number,
): Lane {
// This function is always called inside a microtask, or at the very end of a
// rendering task right before we yield to the main thread. It should never be
// called synchronously.
// This function also never performs React work synchronously; it should
// only schedule work to be performed later, in a separate task or microtask.
// Check if any lanes are being starved by other work. If so, mark them as
// expired so we know to work on those next.
markStarvedLanesAsExpired(root, currentTime);
// Determine the next lanes to work on, and their priority.
const rootWithPendingPassiveEffects = getRootWithPendingPassiveEffects();
const pendingPassiveEffectsLanes = getPendingPassiveEffectsLanes();
const workInProgressRoot = getWorkInProgressRoot();
const workInProgressRootRenderLanes = getWorkInProgressRootRenderLanes();
const rootHasPendingCommit =
root.cancelPendingCommit !== null || root.timeoutHandle !== noTimeout;
const nextLanes =
enableYieldingBeforePassive && root === rootWithPendingPassiveEffects
? // This will schedule the callback at the priority of the lane but we used to
// always schedule it at NormalPriority. Discrete will flush it sync anyway.
// So the only difference is Idle and it doesn't seem necessarily right for that
// to get upgraded beyond something important just because we're past commit.
pendingPassiveEffectsLanes
: getNextLanes(
root,
root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
rootHasPendingCommit,
);
const existingCallbackNode = root.callbackNode;
if (
// Check if there's nothing to work on
nextLanes === NoLanes ||
// If this root is currently suspended and waiting for data to resolve, don't
// schedule a task to render it. We'll either wait for a ping, or wait to
// receive an update.
//
// Suspended render phase
(root === workInProgressRoot && isWorkLoopSuspendedOnData()) ||
// Suspended commit phase
root.cancelPendingCommit !== null
) {
// Fast path: There's nothing to work on.
if (existingCallbackNode !== null) {
cancelCallback(existingCallbackNode);
}
root.callbackNode = null;
root.callbackPriority = NoLane;
return NoLane;
}
// Schedule a new callback in the host environment.
if (
includesSyncLane(nextLanes) &&
// If we're prerendering, then we should use the concurrent work loop
// even if the lanes are synchronous, so that prerendering never blocks
// the main thread.
!checkIfRootIsPrerendering(root, nextLanes)
) {
// Synchronous work is always flushed at the end of the microtask, so we
// don't need to schedule an additional task.
if (existingCallbackNode !== null) {
cancelCallback(existingCallbackNode);
}
root.callbackPriority = SyncLane;
root.callbackNode = null;
return SyncLane;
} else {
// We use the highest priority lane to represent the priority of the callback.
const existingCallbackPriority = root.callbackPriority;
const newCallbackPriority = getHighestPriorityLane(nextLanes);
if (
newCallbackPriority === existingCallbackPriority &&
// Special case related to `act`. If the currently scheduled task is a
Domain
Subdomains
Source
Frequently Asked Questions
What does scheduleTaskForRootDuringMicrotask() do?
scheduleTaskForRootDuringMicrotask() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberRootScheduler.js.
Where is scheduleTaskForRootDuringMicrotask() defined?
scheduleTaskForRootDuringMicrotask() is defined in packages/react-reconciler/src/ReactFiberRootScheduler.js at line 384.
What does scheduleTaskForRootDuringMicrotask() call?
scheduleTaskForRootDuringMicrotask() calls 3 function(s): cancelCallback, lanesToEventPriority, scheduleCallback.
What calls scheduleTaskForRootDuringMicrotask()?
scheduleTaskForRootDuringMicrotask() is called by 2 function(s): performWorkOnRootViaSchedulerTask, processRootScheduleInMicrotask.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free