Home / File/ ReactDOMUpdateBatching.js — react Source File

ReactDOMUpdateBatching.js — react Source File

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

File javascript BabelCompiler Validation 4 imports 3 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3["ReactDOMUpdateBatching.js"]
  74eeea73_e707_14a2_2e53_d0f6ccb65091["ReactDOMControlledComponent.js"]
  0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3 --> 74eeea73_e707_14a2_2e53_d0f6ccb65091
  569171b2_86a8_e848_2d37_406ee0e7f9af["needsStateRestore"]
  0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3 --> 569171b2_86a8_e848_2d37_406ee0e7f9af
  6a30e1eb_6af5_eaa5_dadc_818db12c8f9b["restoreStateIfNeeded"]
  0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3 --> 6a30e1eb_6af5_eaa5_dadc_818db12c8f9b
  ddecbf3f_f337_559f_a83b_7d088cc54c15["ReactFiberReconciler"]
  0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3 --> ddecbf3f_f337_559f_a83b_7d088cc54c15
  816b54e5_c63c_f8b2_68e8_0c637e281f03["DOMPluginEventSystem.js"]
  816b54e5_c63c_f8b2_68e8_0c637e281f03 --> 0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3
  ddc0fe5b_559e_c0f1_b50a_2b1305b3c3d7["ChangeEventPlugin.js"]
  ddc0fe5b_559e_c0f1_b50a_2b1305b3c3d7 --> 0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3
  f81462d0_b06e_fbf9_f1b8_93352f59d5eb["ScrollEndEventPlugin.js"]
  f81462d0_b06e_fbf9_f1b8_93352f59d5eb --> 0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3
  style 0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3 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.
 */

import {
  needsStateRestore,
  restoreStateIfNeeded,
} from './ReactDOMControlledComponent';

import {
  batchedUpdates as batchedUpdatesImpl,
  discreteUpdates as discreteUpdatesImpl,
  flushSyncWork,
} from 'react-reconciler/src/ReactFiberReconciler';

// Used as a way to call batchedUpdates when we don't have a reference to
// the renderer. Such as when we're dispatching events or if third party
// libraries need to call batchedUpdates. Eventually, this API will go away when
// everything is batched by default. We'll then have a similar API to opt-out of
// scheduled work and instead do synchronous work.

let isInsideEventHandler = false;

function finishEventHandler() {
  // Here we wait until all updates have propagated, which is important
  // when using controlled components within layers:
  // https://github.com/facebook/react/issues/1698
  // Then we restore state of any controlled component.
  const controlledComponentsHavePendingUpdates = needsStateRestore();
  if (controlledComponentsHavePendingUpdates) {
    // If a controlled event was fired, we may need to restore the state of
    // the DOM node back to the controlled value. This is necessary when React
    // bails out of the update without touching the DOM.
    // TODO: Restore state in the microtask, after the discrete updates flush,
    // instead of early flushing them here.
    // @TODO Should move to flushSyncWork once legacy mode is removed but since this flushSync
    // flushes passive effects we can't do this yet.
    flushSyncWork();
    restoreStateIfNeeded();
  }
}

export function batchedUpdates(fn, a, b) {
  if (isInsideEventHandler) {
    // If we are currently inside another batch, we need to wait until it
    // fully completes before restoring state.
    return fn(a, b);
  }
  isInsideEventHandler = true;
  try {
    return batchedUpdatesImpl(fn, a, b);
  } finally {
    isInsideEventHandler = false;
    finishEventHandler();
  }
}

// TODO: Replace with flushSync
export function discreteUpdates(fn, a, b, c, d) {
  return discreteUpdatesImpl(fn, a, b, c, d);
}

Domain

Subdomains

Frequently Asked Questions

What does ReactDOMUpdateBatching.js do?
ReactDOMUpdateBatching.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in ReactDOMUpdateBatching.js?
ReactDOMUpdateBatching.js defines 3 function(s): batchedUpdates, discreteUpdates, finishEventHandler.
What does ReactDOMUpdateBatching.js depend on?
ReactDOMUpdateBatching.js imports 4 module(s): ReactDOMControlledComponent.js, ReactFiberReconciler, needsStateRestore, restoreStateIfNeeded.
What files import ReactDOMUpdateBatching.js?
ReactDOMUpdateBatching.js is imported by 3 file(s): ChangeEventPlugin.js, DOMPluginEventSystem.js, ScrollEndEventPlugin.js.
Where is ReactDOMUpdateBatching.js in the architecture?
ReactDOMUpdateBatching.js is located at packages/react-dom-bindings/src/events/ReactDOMUpdateBatching.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-dom-bindings/src/events).

Analyze Your Own Codebase

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

Try Supermodel Free