Home / Function/ updateSuspenseComponent() — react Function Reference

updateSuspenseComponent() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  f4acdab6_f680_af63_8940_0259a68c2f48["updateSuspenseComponent()"]
  0be70812_cc0c_b210_f84f_8e61dd5f831c["ReactFiberBeginWork.js"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|defined in| 0be70812_cc0c_b210_f84f_8e61dd5f831c
  235e1db1_02a4_912f_7d82_ea6636c850c0["beginWork()"]
  235e1db1_02a4_912f_7d82_ea6636c850c0 -->|calls| f4acdab6_f680_af63_8940_0259a68c2f48
  d19e18e7_cb00_83e4_585a_64317da109b2["shouldRemainOnFallback()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| d19e18e7_cb00_83e4_585a_64317da109b2
  dae8f65a_04a5_194b_7c97_c4819e519207["getIsHydrating()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| dae8f65a_04a5_194b_7c97_c4819e519207
  b647f646_ee62_5db9_2e55_81bfe0bcdd6c["pushPrimaryTreeSuspenseHandler()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| b647f646_ee62_5db9_2e55_81bfe0bcdd6c
  0792b4b9_d145_0f54_f5dc_1c2c75771d59["pushFallbackTreeSuspenseHandler()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| 0792b4b9_d145_0f54_f5dc_1c2c75771d59
  063d3886_b682_bfe4_3526_2efd080da924["claimNextHydratableSuspenseInstance()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| 063d3886_b682_bfe4_3526_2efd080da924
  01383193_5efe_365a_bb32_2b8e5399ac5f["mountDehydratedSuspenseComponent()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| 01383193_5efe_365a_bb32_2b8e5399ac5f
  947327cb_b1cb_648e_e70d_a596b230d0c5["mountSuspenseFallbackChildren()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| 947327cb_b1cb_648e_e70d_a596b230d0c5
  73f20134_454b_c241_2ca5_e1c276ddc31d["mountSuspenseOffscreenState()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| 73f20134_454b_c241_2ca5_e1c276ddc31d
  a9bd5488_92fb_77d0_d235_59865a308ccf["getRemainingWorkInPrimaryTree()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| a9bd5488_92fb_77d0_d235_59865a308ccf
  219a3239_d833_17eb_948a_bef7724b5517["bailoutOffscreenComponent()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| 219a3239_d833_17eb_948a_bef7724b5517
  80f1c189_9114_4d52_32dc_752c9920a1de["mountSuspensePrimaryChildren()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| 80f1c189_9114_4d52_32dc_752c9920a1de
  a8a1881a_9da1_7942_71cd_b9ab16efd50c["updateDehydratedSuspenseComponent()"]
  f4acdab6_f680_af63_8940_0259a68c2f48 -->|calls| a8a1881a_9da1_7942_71cd_b9ab16efd50c
  style f4acdab6_f680_af63_8940_0259a68c2f48 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberBeginWork.js lines 2345–2609

function updateSuspenseComponent(
  current: null | Fiber,
  workInProgress: Fiber,
  renderLanes: Lanes,
) {
  const nextProps: SuspenseProps = workInProgress.pendingProps;

  // This is used by DevTools to force a boundary to suspend.
  if (__DEV__) {
    if (shouldSuspend(workInProgress)) {
      workInProgress.flags |= DidCapture;
    }
  }

  let showFallback = false;
  const didSuspend = (workInProgress.flags & DidCapture) !== NoFlags;
  if (
    didSuspend ||
    shouldRemainOnFallback(current, workInProgress, renderLanes)
  ) {
    // Something in this boundary's subtree already suspended. Switch to
    // rendering the fallback children.
    showFallback = true;
    workInProgress.flags &= ~DidCapture;
  }

  // Check if the primary children spawned a deferred task (useDeferredValue)
  // during the first pass.
  const didPrimaryChildrenDefer = (workInProgress.flags & DidDefer) !== NoFlags;
  workInProgress.flags &= ~DidDefer;

  // OK, the next part is confusing. We're about to reconcile the Suspense
  // boundary's children. This involves some custom reconciliation logic. Two
  // main reasons this is so complicated.
  //
  // First, Legacy Mode has different semantics for backwards compatibility. The
  // primary tree will commit in an inconsistent state, so when we do the
  // second pass to render the fallback, we do some exceedingly, uh, clever
  // hacks to make that not totally break. Like transferring effects and
  // deletions from hidden tree. In Concurrent Mode, it's much simpler,
  // because we bailout on the primary tree completely and leave it in its old
  // state, no effects. Same as what we do for Offscreen (except that
  // Offscreen doesn't have the first render pass).
  //
  // Second is hydration. During hydration, the Suspense fiber has a slightly
  // different layout, where the child points to a dehydrated fragment, which
  // contains the DOM rendered by the server.
  //
  // Third, even if you set all that aside, Suspense is like error boundaries in
  // that we first we try to render one tree, and if that fails, we render again
  // and switch to a different tree. Like a try/catch block. So we have to track
  // which branch we're currently rendering. Ideally we would model this using
  // a stack.
  if (current === null) {
    // Initial mount

    // Special path for hydration
    // If we're currently hydrating, try to hydrate this boundary.
    if (getIsHydrating()) {
      // We must push the suspense handler context *before* attempting to
      // hydrate, to avoid a mismatch in case it errors.
      if (showFallback) {
        pushPrimaryTreeSuspenseHandler(workInProgress);
      } else {
        pushFallbackTreeSuspenseHandler(workInProgress);
      }
      // This throws if we fail to hydrate.
      const dehydrated: SuspenseInstance =
        claimNextHydratableSuspenseInstance(workInProgress);
      return mountDehydratedSuspenseComponent(
        workInProgress,
        dehydrated,
        renderLanes,
      );
    }

    const nextPrimaryChildren = nextProps.children;
    const nextFallbackChildren = nextProps.fallback;

    if (showFallback) {
      pushFallbackTreeSuspenseHandler(workInProgress);

Domain

Subdomains

Called By

Frequently Asked Questions

What does updateSuspenseComponent() do?
updateSuspenseComponent() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberBeginWork.js.
Where is updateSuspenseComponent() defined?
updateSuspenseComponent() is defined in packages/react-reconciler/src/ReactFiberBeginWork.js at line 2345.
What does updateSuspenseComponent() call?
updateSuspenseComponent() calls 15 function(s): bailoutOffscreenComponent, claimNextHydratableSuspenseInstance, getIsHydrating, getRemainingWorkInPrimaryTree, mountDehydratedSuspenseComponent, mountSuspenseFallbackChildren, mountSuspenseOffscreenState, mountSuspensePrimaryChildren, and 7 more.
What calls updateSuspenseComponent()?
updateSuspenseComponent() 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