Repository: facebook/react
File: packages/react-reconciler/src/ReactFiberRootScheduler.js (JavaScript)

Code before:
            root,
            root === workInProgressRoot
              ? workInProgressRootRenderLanes
              : NoLanes,
          );
          if (
            includesSyncLane(nextLanes) &&
            !checkIfRootIsPrerendering(root, nextLanes)
          ) {
            // This root has pending sync work. Flush it now.
            didPerformSomeWork = true;
            performSyncWorkOnRoot(root, nextLanes);
          }
        }
      }
      root = root.next;
    }
  } while (didPerformSomeWork);
  isFlushingWork = false;
}

function processRootScheduleInMicrotask() {
  if (enableProfilerTimer && enableComponentPerformanceTrack) {
    // Track the currently executing event if there is one so we can ignore this
    // event when logging events.
    trackSchedulerEvent();
  }

  // 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;
    }
    currentEventTransitionLane = NoLane;
  }

  const currentTime = now();


Review comment (suggestion):
I had to restructure this a bit so that we have two separate callbacks depending on if we do the `Scheduler_scheduleCallback` pass or the microtask pass. Because we shouldn't call `trackSchedulerEvent()` if we're inside a microtask callback because that could mark a real event as if it was a scheduler event (and therefore hidden).

Code after:
            root,
            root === workInProgressRoot
              ? workInProgressRootRenderLanes
              : NoLanes,
          );
          if (
            includesSyncLane(nextLanes) &&
            !checkIfRootIsPrerendering(root, nextLanes)
          ) {
            // This root has pending sync work. Flush it now.
            didPerformSomeWork = true;
            performSyncWorkOnRoot(root, nextLanes);
          }
        }
      }
      root = root.next;
    }
  } while (didPerformSomeWork);
  isFlushingWork = false;
}

function processRootScheduleInImmediateTask() {
  if (enableProfilerTimer && enableComponentPerformanceTrack) {
    // Track the currently executing event if there is one so we can ignore this
    // event when logging events.
    trackSchedulerEvent();
  }

  processRootScheduleInMicrotask();
}

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;
    }
    currentEventTransitionLane = NoLane;