shlogg · Early preview
Ramu Narasinga @karthik-m22

How React Implements Macro Tasks With QueueMacroTask

React's enqueueTask uses queueMacroTask, a MacroTask, to schedule tasks. It checks for Node's setImmediate or browser's MessageChannel implementation.

In this article, we analyze queueMacroTask in React source code.

Although, file and function are named as enqueueTask, it is imported as queueMacroTask. Unlike window.queueMicroTask, there is no function such as window.queueMarcoTask. setTimeout is an example of MacroTask.
Read more about event loop, micro task and macro task.

  
  
  React’s enqueueTask:


/**
 * Copyright © Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */
let didWarnAboutMessageChannel = fals...