Home / File/ ReactDOMFlushSync.js — react Source File

ReactDOMFlushSync.js — react Source File

Architecture documentation for ReactDOMFlushSync.js, a javascript file in the react codebase. 4 imports, 2 dependents.

File javascript BabelCompiler 4 imports 2 dependents

Entity Profile

Dependency Diagram

graph LR
  7c97d39b_70ad_d3ea_12fc_3413f53dc064["ReactDOMFlushSync.js"]
  8344de1b_978c_be0f_eebd_38ccc4962a93["ReactFeatureFlags"]
  7c97d39b_70ad_d3ea_12fc_3413f53dc064 --> 8344de1b_978c_be0f_eebd_38ccc4962a93
  ee448c5a_bbb1_876b_443a_d70daee16237["ReactEventPriorities"]
  7c97d39b_70ad_d3ea_12fc_3413f53dc064 --> ee448c5a_bbb1_876b_443a_d70daee16237
  1c5695a6_6806_ba54_2074_efc779e66da4["ReactSharedInternals"]
  7c97d39b_70ad_d3ea_12fc_3413f53dc064 --> 1c5695a6_6806_ba54_2074_efc779e66da4
  9b61bdad_4620_0f90_ab09_c1efd8c52c41["ReactDOMSharedInternals"]
  7c97d39b_70ad_d3ea_12fc_3413f53dc064 --> 9b61bdad_4620_0f90_ab09_c1efd8c52c41
  1b3f328f_ac2c_6e3e_233b_fbbe5d0412b0["ReactDOMClientFB.js"]
  1b3f328f_ac2c_6e3e_233b_fbbe5d0412b0 --> 7c97d39b_70ad_d3ea_12fc_3413f53dc064
  ca23127c_62b0_2c69_7293_39d92b24a5c0["ReactDOM.js"]
  ca23127c_62b0_2c69_7293_39d92b24a5c0 --> 7c97d39b_70ad_d3ea_12fc_3413f53dc064
  style 7c97d39b_70ad_d3ea_12fc_3413f53dc064 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 {disableLegacyMode} from 'shared/ReactFeatureFlags';
import {DiscreteEventPriority} from 'react-reconciler/src/ReactEventPriorities';

import ReactSharedInternals from 'shared/ReactSharedInternals';

import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';

declare function flushSyncImpl<R>(fn: () => R): R;
declare function flushSyncImpl(void): void;
function flushSyncImpl<R>(fn: (() => R) | void): R | void {
  const previousTransition = ReactSharedInternals.T;
  const previousUpdatePriority =
    ReactDOMSharedInternals.p; /* ReactDOMCurrentUpdatePriority */

  try {
    ReactSharedInternals.T = null;
    ReactDOMSharedInternals.p /* ReactDOMCurrentUpdatePriority */ =
      DiscreteEventPriority;
    if (fn) {
      return fn();
    } else {
      return undefined;
    }
  } finally {
    ReactSharedInternals.T = previousTransition;
    ReactDOMSharedInternals.p /* ReactDOMCurrentUpdatePriority */ =
      previousUpdatePriority;
    const wasInRender =
      ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
        .f(); /* flushSyncWork */
    if (__DEV__) {
      if (wasInRender) {
        console.error(
          'flushSync was called from inside a lifecycle method. React cannot ' +
            'flush when React is already rendering. Consider moving this call to ' +
            'a scheduler task or micro task.',
        );
      }
    }
  }
}

declare function flushSyncErrorInBuildsThatSupportLegacyMode<R>(fn: () => R): R;
declare function flushSyncErrorInBuildsThatSupportLegacyMode(void): void;
function flushSyncErrorInBuildsThatSupportLegacyMode() {
  // eslint-disable-next-line react-internal/prod-error-codes
  throw new Error(
    'Expected this build of React to not support legacy mode but it does. This is a bug in React.',
  );
}

export const flushSync: typeof flushSyncImpl = disableLegacyMode
  ? flushSyncImpl
  : flushSyncErrorInBuildsThatSupportLegacyMode;

Domain

Dependencies

  • ReactDOMSharedInternals
  • ReactEventPriorities
  • ReactFeatureFlags
  • ReactSharedInternals

Frequently Asked Questions

What does ReactDOMFlushSync.js do?
ReactDOMFlushSync.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does ReactDOMFlushSync.js depend on?
ReactDOMFlushSync.js imports 4 module(s): ReactDOMSharedInternals, ReactEventPriorities, ReactFeatureFlags, ReactSharedInternals.
What files import ReactDOMFlushSync.js?
ReactDOMFlushSync.js is imported by 2 file(s): ReactDOM.js, ReactDOMClientFB.js.
Where is ReactDOMFlushSync.js in the architecture?
ReactDOMFlushSync.js is located at packages/react-dom/src/shared/ReactDOMFlushSync.js (domain: BabelCompiler, directory: packages/react-dom/src/shared).

Analyze Your Own Codebase

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

Try Supermodel Free