Home / Function/ completeDehydratedSuspenseBoundary() — react Function Reference

completeDehydratedSuspenseBoundary() — react Function Reference

Architecture documentation for the completeDehydratedSuspenseBoundary() function in ReactFiberCompleteWork.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  f7a91352_2453_8bcd_5056_584b2804cbf7["completeDehydratedSuspenseBoundary()"]
  6b05669d_2f09_63a5_e79f_0afc195f25a3["ReactFiberCompleteWork.js"]
  f7a91352_2453_8bcd_5056_584b2804cbf7 -->|defined in| 6b05669d_2f09_63a5_e79f_0afc195f25a3
  0b8db832_87fd_e560_8aa8_e2b319c81626["completeWork()"]
  0b8db832_87fd_e560_8aa8_e2b319c81626 -->|calls| f7a91352_2453_8bcd_5056_584b2804cbf7
  b741356a_b031_e7cd_ea5d_ed59f056748d["popHydrationState()"]
  f7a91352_2453_8bcd_5056_584b2804cbf7 -->|calls| b741356a_b031_e7cd_ea5d_ed59f056748d
  9bb50f6d_063f_eb0b_1d87_0e1f8510ffb5["prepareToHydrateHostSuspenseInstance()"]
  f7a91352_2453_8bcd_5056_584b2804cbf7 -->|calls| 9bb50f6d_063f_eb0b_1d87_0e1f8510ffb5
  1a7e7cc1_6419_de9c_0611_6890ef404e66["bubbleProperties()"]
  f7a91352_2453_8bcd_5056_584b2804cbf7 -->|calls| 1a7e7cc1_6419_de9c_0611_6890ef404e66
  87c1044e_4880_6c4c_bb78_f18f233bb260["resetHydrationState()"]
  f7a91352_2453_8bcd_5056_584b2804cbf7 -->|calls| 87c1044e_4880_6c4c_bb78_f18f233bb260
  style f7a91352_2453_8bcd_5056_584b2804cbf7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberCompleteWork.js lines 986–1066

function completeDehydratedSuspenseBoundary(
  current: Fiber | null,
  workInProgress: Fiber,
  nextState: SuspenseState | null,
): boolean {
  const wasHydrated = popHydrationState(workInProgress);

  if (nextState !== null && nextState.dehydrated !== null) {
    // We might be inside a hydration state the first time we're picking up this
    // Suspense boundary, and also after we've reentered it for further hydration.
    if (current === null) {
      if (!wasHydrated) {
        throw new Error(
          'A dehydrated suspense component was completed without a hydrated node. ' +
            'This is probably a bug in React.',
        );
      }
      prepareToHydrateHostSuspenseInstance(workInProgress);
      bubbleProperties(workInProgress);
      if (enableProfilerTimer) {
        if ((workInProgress.mode & ProfileMode) !== NoMode) {
          const isTimedOutSuspense = nextState !== null;
          if (isTimedOutSuspense) {
            // Don't count time spent in a timed out Suspense subtree as part of the base duration.
            const primaryChildFragment = workInProgress.child;
            if (primaryChildFragment !== null) {
              // $FlowFixMe[unsafe-arithmetic] Flow doesn't support type casting in combination with the -= operator
              workInProgress.treeBaseDuration -=
                ((primaryChildFragment.treeBaseDuration: any): number);
            }
          }
        }
      }
      return false;
    } else {
      emitPendingHydrationWarnings();
      // We might have reentered this boundary to hydrate it. If so, we need to reset the hydration
      // state since we're now exiting out of it. popHydrationState doesn't do that for us.
      resetHydrationState();
      if ((workInProgress.flags & DidCapture) === NoFlags) {
        // This boundary did not suspend so it's now hydrated and unsuspended.
        nextState = workInProgress.memoizedState = null;
      }
      // If nothing suspended, we need to schedule an effect to mark this boundary
      // as having hydrated so events know that they're free to be invoked.
      // It's also a signal to replay events and the suspense callback.
      // If something suspended, schedule an effect to attach retry listeners.
      // So we might as well always mark this.
      workInProgress.flags |= Update;
      bubbleProperties(workInProgress);
      if (enableProfilerTimer) {
        if ((workInProgress.mode & ProfileMode) !== NoMode) {
          const isTimedOutSuspense = nextState !== null;
          if (isTimedOutSuspense) {
            // Don't count time spent in a timed out Suspense subtree as part of the base duration.
            const primaryChildFragment = workInProgress.child;
            if (primaryChildFragment !== null) {
              // $FlowFixMe[unsafe-arithmetic] Flow doesn't support type casting in combination with the -= operator
              workInProgress.treeBaseDuration -=
                ((primaryChildFragment.treeBaseDuration: any): number);
            }
          }
        }
      }
      return false;
    }
  } else {
    // Successfully completed this tree. If this was a forced client render,
    // there may have been recoverable errors during first hydration
    // attempt. If so, add them to a queue so we can log them in the
    // commit phase. We also add them to prev state so we can get to them
    // from the Suspense Boundary.
    const hydrationErrors = upgradeHydrationErrorsToRecoverable();
    if (current !== null && current.memoizedState !== null) {
      const prevState: SuspenseState = current.memoizedState;
      prevState.hydrationErrors = hydrationErrors;
    }
    // Fall through to normal Suspense path
    return true;
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does completeDehydratedSuspenseBoundary() do?
completeDehydratedSuspenseBoundary() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberCompleteWork.js.
Where is completeDehydratedSuspenseBoundary() defined?
completeDehydratedSuspenseBoundary() is defined in packages/react-reconciler/src/ReactFiberCompleteWork.js at line 986.
What does completeDehydratedSuspenseBoundary() call?
completeDehydratedSuspenseBoundary() calls 4 function(s): bubbleProperties, popHydrationState, prepareToHydrateHostSuspenseInstance, resetHydrationState.
What calls completeDehydratedSuspenseBoundary()?
completeDehydratedSuspenseBoundary() is called by 1 function(s): completeWork.

Analyze Your Own Codebase

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

Try Supermodel Free