Home / File/ ReactAct.js — react Source File

ReactAct.js — react Source File

Architecture documentation for ReactAct.js, a javascript file in the react codebase. 5 imports, 1 dependents.

File javascript BabelCompiler 5 imports 1 dependents

Entity Profile

Dependency Diagram

graph LR
  32ddd28a_4f69_b50e_08f3_813512cb1996["ReactAct.js"]
  d73e8952_8d9a_9536_f6d1_89e62a9194a3["ReactSharedInternalsClient.js"]
  32ddd28a_4f69_b50e_08f3_813512cb1996 --> d73e8952_8d9a_9536_f6d1_89e62a9194a3
  2be5af4a_089e_0bf8_1a00_0ff12580d87b["ReactSharedInternals"]
  32ddd28a_4f69_b50e_08f3_813512cb1996 --> 2be5af4a_089e_0bf8_1a00_0ff12580d87b
  d8f20c67_f5fa_0f0a_c967_c41fd9ffce07["ReactTypes"]
  32ddd28a_4f69_b50e_08f3_813512cb1996 --> d8f20c67_f5fa_0f0a_c967_c41fd9ffce07
  fe07fc77_b93c_ea23_07f9_29e1b550bbf1["enqueueTask"]
  32ddd28a_4f69_b50e_08f3_813512cb1996 --> fe07fc77_b93c_ea23_07f9_29e1b550bbf1
  8344de1b_978c_be0f_eebd_38ccc4962a93["ReactFeatureFlags"]
  32ddd28a_4f69_b50e_08f3_813512cb1996 --> 8344de1b_978c_be0f_eebd_38ccc4962a93
  ffdf54f0_7e34_f1e9_1504_9dbadb0fbac5["ReactClient.js"]
  ffdf54f0_7e34_f1e9_1504_9dbadb0fbac5 --> 32ddd28a_4f69_b50e_08f3_813512cb1996
  style 32ddd28a_4f69_b50e_08f3_813512cb1996 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) 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
 */

import type {Thenable} from 'shared/ReactTypes';
import type {RendererTask} from './ReactSharedInternalsClient';
import ReactSharedInternals from './ReactSharedInternalsClient';
import queueMacrotask from 'shared/enqueueTask';

import {disableLegacyMode} from 'shared/ReactFeatureFlags';

// `act` calls can be nested, so we track the depth. This represents the
// number of `act` scopes on the stack.
let actScopeDepth = 0;

// We only warn the first time you neglect to await an async `act` scope.
let didWarnNoAwaitAct = false;

function aggregateErrors(errors: Array<mixed>): mixed {
  if (errors.length > 1 && typeof AggregateError === 'function') {
    // eslint-disable-next-line no-undef
    return new AggregateError(errors);
  }
  return errors[0];
}

export function act<T>(callback: () => T | Thenable<T>): Thenable<T> {
  if (__DEV__) {
    // When ReactSharedInternals.actQueue is not null, it signals to React that
    // we're currently inside an `act` scope. React will push all its tasks to
    // this queue instead of scheduling them with platform APIs.
    //
    // We set this to an empty array when we first enter an `act` scope, and
    // only unset it once we've left the outermost `act` scope — remember that
    // `act` calls can be nested.
    //
    // If we're already inside an `act` scope, reuse the existing queue.
    const prevIsBatchingLegacy = !disableLegacyMode
      ? ReactSharedInternals.isBatchingLegacy
      : false;
    const prevActQueue = ReactSharedInternals.actQueue;
    const prevActScopeDepth = actScopeDepth;
    actScopeDepth++;
    const queue = (ReactSharedInternals.actQueue =
      prevActQueue !== null ? prevActQueue : []);
    // Used to reproduce behavior of `batchedUpdates` in legacy mode. Only
    // set to `true` while the given callback is executed, not for updates
    // triggered during an async event, because this is how the legacy
    // implementation of `act` behaved.
    if (!disableLegacyMode) {
      ReactSharedInternals.isBatchingLegacy = true;
    }

    let result;
    // This tracks whether the `act` call is awaited. In certain cases, not
// ... (307 more lines)

Domain

Dependencies

Frequently Asked Questions

What does ReactAct.js do?
ReactAct.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does ReactAct.js depend on?
ReactAct.js imports 5 module(s): ReactFeatureFlags, ReactSharedInternals, ReactSharedInternalsClient.js, ReactTypes, enqueueTask.
What files import ReactAct.js?
ReactAct.js is imported by 1 file(s): ReactClient.js.
Where is ReactAct.js in the architecture?
ReactAct.js is located at packages/react/src/ReactAct.js (domain: BabelCompiler, directory: packages/react/src).

Analyze Your Own Codebase

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

Try Supermodel Free