Home / File/ ReactDOMFragmentRefShared.js — react Source File

ReactDOMFragmentRefShared.js — react Source File

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

File javascript 2 imports

Entity Profile

Dependency Diagram

graph LR
  3c230bbd_62ef_7989_b499_4bc8a90ec74b["ReactDOMFragmentRefShared.js"]
  42892443_e223_3da0_aeb9_e1b32a408fb0["ReactInternalTypes"]
  3c230bbd_62ef_7989_b499_4bc8a90ec74b --> 42892443_e223_3da0_aeb9_e1b32a408fb0
  7f19218b_4899_62d7_ffe7_3eef935f36ce["ReactFiberTreeReflection"]
  3c230bbd_62ef_7989_b499_4bc8a90ec74b --> 7f19218b_4899_62d7_ffe7_3eef935f36ce
  style 3c230bbd_62ef_7989_b499_4bc8a90ec74b 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.
 *
 * Shared logic for Fragment Ref operations for DOM and Fabric configs
 *
 * @flow
 */

import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';

import {getNextSiblingHostFiber} from 'react-reconciler/src/ReactFiberTreeReflection';

export function compareDocumentPositionForEmptyFragment<TPublicInstance>(
  fragmentFiber: Fiber,
  parentHostInstance: TPublicInstance,
  otherNode: TPublicInstance,
  getPublicInstance: (fiber: Fiber) => TPublicInstance,
): number {
  let result;
  // If the fragment has no children, we can use the parent and
  // siblings to determine a position.
  // $FlowFixMe[incompatible-use] Fabric PublicInstance is opaque
  // $FlowFixMe[prop-missing]
  const parentResult = parentHostInstance.compareDocumentPosition(otherNode);
  result = parentResult;
  if (parentHostInstance === otherNode) {
    result = Node.DOCUMENT_POSITION_CONTAINS;
  } else {
    if (parentResult & Node.DOCUMENT_POSITION_CONTAINED_BY) {
      // otherNode is one of the fragment's siblings. Use the next
      // sibling to determine if its preceding or following.
      const nextSiblingFiber = getNextSiblingHostFiber(fragmentFiber);
      if (nextSiblingFiber === null) {
        result = Node.DOCUMENT_POSITION_PRECEDING;
      } else {
        const nextSiblingInstance = getPublicInstance(nextSiblingFiber);
        const nextSiblingResult =
          // $FlowFixMe[incompatible-use] Fabric PublicInstance is opaque
          // $FlowFixMe[prop-missing]
          nextSiblingInstance.compareDocumentPosition(otherNode);
        if (
          nextSiblingResult === 0 ||
          nextSiblingResult & Node.DOCUMENT_POSITION_FOLLOWING
        ) {
          result = Node.DOCUMENT_POSITION_FOLLOWING;
        } else {
          result = Node.DOCUMENT_POSITION_PRECEDING;
        }
      }
    }
  }

  result |= Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
  return result;
}

Dependencies

  • ReactFiberTreeReflection
  • ReactInternalTypes

Frequently Asked Questions

What does ReactDOMFragmentRefShared.js do?
ReactDOMFragmentRefShared.js is a source file in the react codebase, written in javascript.
What does ReactDOMFragmentRefShared.js depend on?
ReactDOMFragmentRefShared.js imports 2 module(s): ReactFiberTreeReflection, ReactInternalTypes.
Where is ReactDOMFragmentRefShared.js in the architecture?
ReactDOMFragmentRefShared.js is located at packages/shared/ReactDOMFragmentRefShared.js (directory: packages/shared).

Analyze Your Own Codebase

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

Try Supermodel Free