Home / Function/ updateHostRoot() — react Function Reference

updateHostRoot() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  53f55fda_e2b6_2801_4fbc_525f8828d23d["updateHostRoot()"]
  0be70812_cc0c_b210_f84f_8e61dd5f831c["ReactFiberBeginWork.js"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|defined in| 0be70812_cc0c_b210_f84f_8e61dd5f831c
  235e1db1_02a4_912f_7d82_ea6636c850c0["beginWork()"]
  235e1db1_02a4_912f_7d82_ea6636c850c0 -->|calls| 53f55fda_e2b6_2801_4fbc_525f8828d23d
  709caba0_6dab_3197_d227_28b3fa3a6dc4["pushHostRootContext()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| 709caba0_6dab_3197_d227_28b3fa3a6dc4
  697e1943_fa13_4adb_b6f2_f2eba2051634["pushRootMarkerInstance()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| 697e1943_fa13_4adb_b6f2_f2eba2051634
  554cee68_4cbf_1f39_7875_14cfa10442ae["pushCacheProvider()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| 554cee68_4cbf_1f39_7875_14cfa10442ae
  74eacdb2_209e_147d_3ef0_549f29526913["enterHydrationState()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| 74eacdb2_209e_147d_3ef0_549f29526913
  87c1044e_4880_6c4c_bb78_f18f233bb260["resetHydrationState()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| 87c1044e_4880_6c4c_bb78_f18f233bb260
  6cb202e6_76dc_0479_ff31_d0ef23610882["bailoutOnAlreadyFinishedWork()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| 6cb202e6_76dc_0479_ff31_d0ef23610882
  cf5641cc_b89e_d6b2_5d40_41ad5bbdd682["reconcileChildren()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| cf5641cc_b89e_d6b2_5d40_41ad5bbdd682
  ae7022cd_2911_01f4_d595_3b71fd40d093["tryToClaimNextHydratableInstance()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| ae7022cd_2911_01f4_d595_3b71fd40d093
  a05eb624_1205_fe14_d003_611163eae529["pushHostContext()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| a05eb624_1205_fe14_d003_611163eae529
  add16f45_ce6d_6414_6371_4a68ab583d28["markRef()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| add16f45_ce6d_6414_6371_4a68ab583d28
  dae8f65a_04a5_194b_7c97_c4819e519207["getIsHydrating()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| dae8f65a_04a5_194b_7c97_c4819e519207
  caaf30b2_6e58_ce4e_f73c_baa2c3b083d0["getRootHostContainer()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| caaf30b2_6e58_ce4e_f73c_baa2c3b083d0
  style 53f55fda_e2b6_2801_4fbc_525f8828d23d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberBeginWork.js lines 1797–2171

function updateHostRoot(
  current: null | Fiber,
  workInProgress: Fiber,
  renderLanes: Lanes,
) {
  pushHostRootContext(workInProgress);

  if (current === null) {
    throw new Error('Should have a current fiber. This is a bug in React.');
  }

  const nextProps = workInProgress.pendingProps;
  const prevState: RootState = workInProgress.memoizedState;
  const prevChildren = prevState.element;
  cloneUpdateQueue(current, workInProgress);
  processUpdateQueue(workInProgress, nextProps, null, renderLanes);

  const nextState: RootState = workInProgress.memoizedState;
  const root: FiberRoot = workInProgress.stateNode;
  pushRootTransition(workInProgress, root, renderLanes);

  if (enableTransitionTracing) {
    pushRootMarkerInstance(workInProgress);
  }

  const nextCache: Cache = nextState.cache;
  pushCacheProvider(workInProgress, nextCache);
  if (nextCache !== prevState.cache) {
    // The root cache refreshed.
    propagateContextChange(workInProgress, CacheContext, renderLanes);
  }

  // This would ideally go inside processUpdateQueue, but because it suspends,
  // it needs to happen after the `pushCacheProvider` call above to avoid a
  // context stack mismatch. A bit unfortunate.
  suspendIfUpdateReadFromEntangledAsyncAction();

  // Caution: React DevTools currently depends on this property
  // being called "element".
  const nextChildren = nextState.element;
  if (supportsHydration && prevState.isDehydrated) {
    // This is a hydration root whose shell has not yet hydrated. We should
    // attempt to hydrate.

    // Flip isDehydrated to false to indicate that when this render
    // finishes, the root will no longer be dehydrated.
    const overrideState: RootState = {
      element: nextChildren,
      isDehydrated: false,
      cache: nextState.cache,
    };
    const updateQueue: UpdateQueue<RootState> =
      (workInProgress.updateQueue: any);
    // `baseState` can always be the last state because the root doesn't
    // have reducer functions so it doesn't need rebasing.
    updateQueue.baseState = overrideState;
    workInProgress.memoizedState = overrideState;

    if (workInProgress.flags & ForceClientRender) {
      // Something errored during a previous attempt to hydrate the shell, so we
      // forced a client render. We should have a recoverable error already scheduled.
      return mountHostRootWithoutHydrating(
        current,
        workInProgress,
        nextChildren,
        renderLanes,
      );
    } else if (nextChildren !== prevChildren) {
      const recoverableError = createCapturedValueAtFiber<mixed>(
        new Error(
          'This root received an early update, before anything was able ' +
            'hydrate. Switched the entire root to client rendering.',
        ),
        workInProgress,
      );
      queueHydrationError(recoverableError);
      return mountHostRootWithoutHydrating(
        current,
        workInProgress,
        nextChildren,
        renderLanes,

Domain

Subdomains

Called By

Frequently Asked Questions

What does updateHostRoot() do?
updateHostRoot() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberBeginWork.js.
Where is updateHostRoot() defined?
updateHostRoot() is defined in packages/react-reconciler/src/ReactFiberBeginWork.js at line 1797.
What does updateHostRoot() call?
updateHostRoot() calls 25 function(s): bailoutOnAlreadyFinishedWork, claimHydratableSingleton, enterHydrationState, getIsHydrating, getRootHostContainer, markRef, pushCacheProvider, pushHostContext, and 17 more.
What calls updateHostRoot()?
updateHostRoot() is called by 1 function(s): beginWork.

Analyze Your Own Codebase

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

Try Supermodel Free