Home / Function/ updateOffscreenComponent() — react Function Reference

updateOffscreenComponent() — react Function Reference

Architecture documentation for the updateOffscreenComponent() function in ReactFiberBeginWork.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  526a99f2_4938_2b27_2b9e_a0a59903cdb5["updateOffscreenComponent()"]
  0be70812_cc0c_b210_f84f_8e61dd5f831c["ReactFiberBeginWork.js"]
  526a99f2_4938_2b27_2b9e_a0a59903cdb5 -->|defined in| 0be70812_cc0c_b210_f84f_8e61dd5f831c
  5321231b_2ff1_24fd_d181_f53cdf233503["updateLegacyHiddenComponent()"]
  5321231b_2ff1_24fd_d181_f53cdf233503 -->|calls| 526a99f2_4938_2b27_2b9e_a0a59903cdb5
  235e1db1_02a4_912f_7d82_ea6636c850c0["beginWork()"]
  235e1db1_02a4_912f_7d82_ea6636c850c0 -->|calls| 526a99f2_4938_2b27_2b9e_a0a59903cdb5
  9667b43a_5b5c_621a_f700_b7578247ef20["deferHiddenOffscreenComponent()"]
  526a99f2_4938_2b27_2b9e_a0a59903cdb5 -->|calls| 9667b43a_5b5c_621a_f700_b7578247ef20
  bd22193d_8474_6563_1d9d_425de4fe8986["reuseHiddenContextOnStack()"]
  526a99f2_4938_2b27_2b9e_a0a59903cdb5 -->|calls| bd22193d_8474_6563_1d9d_425de4fe8986
  992f4e57_663a_57fc_8711_c7a964a2cb1c["pushOffscreenSuspenseHandler()"]
  526a99f2_4938_2b27_2b9e_a0a59903cdb5 -->|calls| 992f4e57_663a_57fc_8711_c7a964a2cb1c
  f69f1aac_4142_c319_3eb1_b7142dd9a221["pushHiddenContext()"]
  526a99f2_4938_2b27_2b9e_a0a59903cdb5 -->|calls| f69f1aac_4142_c319_3eb1_b7142dd9a221
  d0fa82b3_bb84_ac45_2b0b_a81afe160a95["reuseSuspenseHandlerOnStack()"]
  526a99f2_4938_2b27_2b9e_a0a59903cdb5 -->|calls| d0fa82b3_bb84_ac45_2b0b_a81afe160a95
  cf5641cc_b89e_d6b2_5d40_41ad5bbdd682["reconcileChildren()"]
  526a99f2_4938_2b27_2b9e_a0a59903cdb5 -->|calls| cf5641cc_b89e_d6b2_5d40_41ad5bbdd682
  style 526a99f2_4938_2b27_2b9e_a0a59903cdb5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberBeginWork.js lines 612–804

function updateOffscreenComponent(
  current: Fiber | null,
  workInProgress: Fiber,
  renderLanes: Lanes,
  nextProps: OffscreenProps,
) {
  const nextChildren = nextProps.children;

  const prevState: OffscreenState | null =
    current !== null ? current.memoizedState : null;

  if (current === null && workInProgress.stateNode === null) {
    // We previously reset the work-in-progress.
    // We need to create a new Offscreen instance.
    const primaryChildInstance: OffscreenInstance = {
      _visibility: OffscreenVisible,
      _pendingMarkers: null,
      _retryCache: null,
      _transitions: null,
    };
    workInProgress.stateNode = primaryChildInstance;
  }

  if (
    nextProps.mode === 'hidden' ||
    (enableLegacyHidden && nextProps.mode === 'unstable-defer-without-hiding')
  ) {
    // Rendering a hidden tree.

    const didSuspend = (workInProgress.flags & DidCapture) !== NoFlags;
    if (didSuspend) {
      // Something suspended inside a hidden tree

      // Include the base lanes from the last render
      const nextBaseLanes =
        prevState !== null
          ? mergeLanes(prevState.baseLanes, renderLanes)
          : renderLanes;

      let remainingChildLanes;
      if (current !== null) {
        // Reset to the current children
        let currentChild = (workInProgress.child = current.child);

        // The current render suspended, but there may be other lanes with
        // pending work. We can't read `childLanes` from the current Offscreen
        // fiber because we reset it when it was deferred; however, we can read
        // the pending lanes from the child fibers.
        let currentChildLanes: Lanes = NoLanes;
        while (currentChild !== null) {
          currentChildLanes = mergeLanes(
            mergeLanes(currentChildLanes, currentChild.lanes),
            currentChild.childLanes,
          );
          currentChild = currentChild.sibling;
        }
        const lanesWeJustAttempted = nextBaseLanes;
        remainingChildLanes = removeLanes(
          currentChildLanes,
          lanesWeJustAttempted,
        );
      } else {
        remainingChildLanes = NoLanes;
        workInProgress.child = null;
      }

      return deferHiddenOffscreenComponent(
        current,
        workInProgress,
        nextBaseLanes,
        renderLanes,
        remainingChildLanes,
      );
    }

    if (
      !disableLegacyMode &&
      (workInProgress.mode & ConcurrentMode) === NoMode
    ) {
      // In legacy sync mode, don't defer the subtree. Render it now.
      // TODO: Consider how Offscreen should work with transitions in the future

Domain

Subdomains

Frequently Asked Questions

What does updateOffscreenComponent() do?
updateOffscreenComponent() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberBeginWork.js.
Where is updateOffscreenComponent() defined?
updateOffscreenComponent() is defined in packages/react-reconciler/src/ReactFiberBeginWork.js at line 612.
What does updateOffscreenComponent() call?
updateOffscreenComponent() calls 6 function(s): deferHiddenOffscreenComponent, pushHiddenContext, pushOffscreenSuspenseHandler, reconcileChildren, reuseHiddenContextOnStack, reuseSuspenseHandlerOnStack.
What calls updateOffscreenComponent()?
updateOffscreenComponent() is called by 2 function(s): beginWork, updateLegacyHiddenComponent.

Analyze Your Own Codebase

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

Try Supermodel Free