Home / File/ ReactDOMControlledComponent.js — react Source File

ReactDOMControlledComponent.js — react Source File

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

File javascript BabelCompiler Validation 2 imports 2 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  74eeea73_e707_14a2_2e53_d0f6ccb65091["ReactDOMControlledComponent.js"]
  799a7834_f34c_8596_4026_015681eee732["ReactDOMComponentTree.js"]
  74eeea73_e707_14a2_2e53_d0f6ccb65091 --> 799a7834_f34c_8596_4026_015681eee732
  f8fe53ea_ec06_fd1b_2491_8c3cfc19e52f["ReactDOMComponent"]
  74eeea73_e707_14a2_2e53_d0f6ccb65091 --> f8fe53ea_ec06_fd1b_2491_8c3cfc19e52f
  0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3["ReactDOMUpdateBatching.js"]
  0d9ca2c0_8ba8_d861_ef7c_cea0ecdd2aa3 --> 74eeea73_e707_14a2_2e53_d0f6ccb65091
  ddc0fe5b_559e_c0f1_b50a_2b1305b3c3d7["ChangeEventPlugin.js"]
  ddc0fe5b_559e_c0f1_b50a_2b1305b3c3d7 --> 74eeea73_e707_14a2_2e53_d0f6ccb65091
  style 74eeea73_e707_14a2_2e53_d0f6ccb65091 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 {
  getInstanceFromNode,
  getFiberCurrentPropsFromNode,
} from '../client/ReactDOMComponentTree';

import {restoreControlledState} from 'react-dom-bindings/src/client/ReactDOMComponent';

// Use to restore controlled state after a change event has fired.

let restoreTarget = null;
let restoreQueue = null;

function restoreStateOfTarget(target: Node) {
  // We perform this translation at the end of the event loop so that we
  // always receive the correct fiber here
  const internalInstance = getInstanceFromNode(target);
  if (!internalInstance) {
    // Unmounted
    return;
  }

  const stateNode = internalInstance.stateNode;
  // Guard against Fiber being unmounted.
  if (stateNode) {
    const props = getFiberCurrentPropsFromNode(stateNode);
    restoreControlledState(
      internalInstance.stateNode,
      internalInstance.type,
      props,
    );
  }
}

export function enqueueStateRestore(target: Node): void {
  if (restoreTarget) {
    if (restoreQueue) {
      restoreQueue.push(target);
    } else {
      restoreQueue = [target];
    }
  } else {
    restoreTarget = target;
  }
}

export function needsStateRestore(): boolean {
  return restoreTarget !== null || restoreQueue !== null;
}

export function restoreStateIfNeeded() {
  if (!restoreTarget) {
    return;
  }
  const target = restoreTarget;
  const queuedTargets = restoreQueue;
  restoreTarget = null;
  restoreQueue = null;

  restoreStateOfTarget(target);
  if (queuedTargets) {
    for (let i = 0; i < queuedTargets.length; i++) {
      restoreStateOfTarget(queuedTargets[i]);
    }
  }
}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does ReactDOMControlledComponent.js do?
ReactDOMControlledComponent.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 ReactDOMControlledComponent.js?
ReactDOMControlledComponent.js defines 4 function(s): enqueueStateRestore, needsStateRestore, restoreStateIfNeeded, restoreStateOfTarget.
What does ReactDOMControlledComponent.js depend on?
ReactDOMControlledComponent.js imports 2 module(s): ReactDOMComponent, ReactDOMComponentTree.js.
What files import ReactDOMControlledComponent.js?
ReactDOMControlledComponent.js is imported by 2 file(s): ChangeEventPlugin.js, ReactDOMUpdateBatching.js.
Where is ReactDOMControlledComponent.js in the architecture?
ReactDOMControlledComponent.js is located at packages/react-dom-bindings/src/events/ReactDOMControlledComponent.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