Home / Function/ commitDeletionEffects() — react Function Reference

commitDeletionEffects() — react Function Reference

Architecture documentation for the commitDeletionEffects() function in ReactFiberCommitWork.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  13f145c1_d686_f120_13ad_212f75386c29["commitDeletionEffects()"]
  e0fbfbd5_47b0_a489_0b36_bbfad9245544["ReactFiberCommitWork.js"]
  13f145c1_d686_f120_13ad_212f75386c29 -->|defined in| e0fbfbd5_47b0_a489_0b36_bbfad9245544
  c588ccff_afbe_0cc8_1f99_6d2d5c3a7a99["recursivelyTraverseMutationEffects()"]
  c588ccff_afbe_0cc8_1f99_6d2d5c3a7a99 -->|calls| 13f145c1_d686_f120_13ad_212f75386c29
  4f76ed87_f151_2295_8bb4_c7b5dfe010a2["pushComponentEffectStart()"]
  13f145c1_d686_f120_13ad_212f75386c29 -->|calls| 4f76ed87_f151_2295_8bb4_c7b5dfe010a2
  5af9a16a_ed89_d37e_b847_bcb6a2805eae["commitDeletionEffectsOnFiber()"]
  13f145c1_d686_f120_13ad_212f75386c29 -->|calls| 5af9a16a_ed89_d37e_b847_bcb6a2805eae
  ff9409a2_b556_06af_85c9_ee748a528d80["popComponentEffectStart()"]
  13f145c1_d686_f120_13ad_212f75386c29 -->|calls| ff9409a2_b556_06af_85c9_ee748a528d80
  ec84cfbd_70a6_4a14_76df_85ddaeb139f7["detachFiberMutation()"]
  13f145c1_d686_f120_13ad_212f75386c29 -->|calls| ec84cfbd_70a6_4a14_76df_85ddaeb139f7
  style 13f145c1_d686_f120_13ad_212f75386c29 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberCommitWork.js lines 1362–1449

function commitDeletionEffects(
  root: FiberRoot,
  returnFiber: Fiber,
  deletedFiber: Fiber,
) {
  const prevEffectStart = pushComponentEffectStart();

  if (supportsMutation) {
    // We only have the top Fiber that was deleted but we need to recurse down its
    // children to find all the terminal nodes.

    // Recursively delete all host nodes from the parent, detach refs, clean
    // up mounted layout effects, and call componentWillUnmount.

    // We only need to remove the topmost host child in each branch. But then we
    // still need to keep traversing to unmount effects, refs, and cWU. TODO: We
    // could split this into two separate traversals functions, where the second
    // one doesn't include any removeChild logic. This is maybe the same
    // function as "disappearLayoutEffects" (or whatever that turns into after
    // the layout phase is refactored to use recursion).

    // Before starting, find the nearest host parent on the stack so we know
    // which instance/container to remove the children from.
    // TODO: Instead of searching up the fiber return path on every deletion, we
    // can track the nearest host component on the JS stack as we traverse the
    // tree during the commit phase. This would make insertions faster, too.
    let parent: null | Fiber = returnFiber;
    findParent: while (parent !== null) {
      switch (parent.tag) {
        case HostSingleton: {
          if (supportsSingletons) {
            if (isSingletonScope(parent.type)) {
              hostParent = parent.stateNode;
              hostParentIsContainer = false;
              break findParent;
            }
            break;
          }
          // Expected fallthrough when supportsSingletons is false
        }
        case HostComponent: {
          hostParent = parent.stateNode;
          hostParentIsContainer = false;
          break findParent;
        }
        case HostRoot:
        case HostPortal: {
          hostParent = parent.stateNode.containerInfo;
          hostParentIsContainer = true;
          break findParent;
        }
      }
      parent = parent.return;
    }
    if (hostParent === null) {
      throw new Error(
        'Expected to find a host parent. This error is likely caused by ' +
          'a bug in React. Please file an issue.',
      );
    }

    commitDeletionEffectsOnFiber(root, returnFiber, deletedFiber);
    hostParent = null;
    hostParentIsContainer = false;
  } else {
    // Detach refs and call componentWillUnmount() on the whole subtree.
    commitDeletionEffectsOnFiber(root, returnFiber, deletedFiber);
  }

  if (
    enableProfilerTimer &&
    enableProfilerCommitHooks &&
    enableComponentPerformanceTrack &&
    (deletedFiber.mode & ProfileMode) !== NoMode &&
    componentEffectStartTime >= 0 &&
    componentEffectEndTime >= 0 &&
    componentEffectEndTime - componentEffectStartTime > 0.05
  ) {
    logComponentUnmount(
      deletedFiber,
      componentEffectStartTime,

Domain

Subdomains

Frequently Asked Questions

What does commitDeletionEffects() do?
commitDeletionEffects() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberCommitWork.js.
Where is commitDeletionEffects() defined?
commitDeletionEffects() is defined in packages/react-reconciler/src/ReactFiberCommitWork.js at line 1362.
What does commitDeletionEffects() call?
commitDeletionEffects() calls 4 function(s): commitDeletionEffectsOnFiber, detachFiberMutation, popComponentEffectStart, pushComponentEffectStart.
What calls commitDeletionEffects()?
commitDeletionEffects() is called by 1 function(s): recursivelyTraverseMutationEffects.

Analyze Your Own Codebase

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

Try Supermodel Free