Home / Function/ commitAfterMutationEffectsOnFiber() — react Function Reference

commitAfterMutationEffectsOnFiber() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  a3d95486_4c2c_708b_ddfb_88e41b6a4967["commitAfterMutationEffectsOnFiber()"]
  e0fbfbd5_47b0_a489_0b36_bbfad9245544["ReactFiberCommitWork.js"]
  a3d95486_4c2c_708b_ddfb_88e41b6a4967 -->|defined in| e0fbfbd5_47b0_a489_0b36_bbfad9245544
  5eef3613_c337_b91f_33e1_b3101f357ba3["commitAfterMutationEffects()"]
  5eef3613_c337_b91f_33e1_b3101f357ba3 -->|calls| a3d95486_4c2c_708b_ddfb_88e41b6a4967
  762bc1dc_3315_21f8_70be_1222a5fd783c["recursivelyTraverseAfterMutationEffects()"]
  762bc1dc_3315_21f8_70be_1222a5fd783c -->|calls| a3d95486_4c2c_708b_ddfb_88e41b6a4967
  762bc1dc_3315_21f8_70be_1222a5fd783c["recursivelyTraverseAfterMutationEffects()"]
  a3d95486_4c2c_708b_ddfb_88e41b6a4967 -->|calls| 762bc1dc_3315_21f8_70be_1222a5fd783c
  style a3d95486_4c2c_708b_ddfb_88e41b6a4967 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberCommitWork.js lines 2805–2950

function commitAfterMutationEffectsOnFiber(
  finishedWork: Fiber,
  root: FiberRoot,
  lanes: Lanes,
) {
  const current = finishedWork.alternate;
  if (current === null) {
    // This is a newly inserted subtree. We can't use Placement flags to detect
    // this since they get removed in the mutation phase. Usually it's not enough
    // to just check current because that can also happen deeper in the same tree.
    // However, since we don't need to visit newly inserted subtrees in AfterMutation
    // we can just bail after we're done with the first one.
    // The first ViewTransition inside a newly mounted tree runs an enter transition
    // but other nested ones don't unless they have a named pair.
    commitEnterViewTransitions(finishedWork, false);
    return;
  }

  switch (finishedWork.tag) {
    case HostRoot: {
      viewTransitionContextChanged = false;
      rootViewTransitionNameCanceled = false;
      pushViewTransitionCancelableScope();
      recursivelyTraverseAfterMutationEffects(root, finishedWork, lanes);
      if (!viewTransitionContextChanged && !rootViewTransitionAffected) {
        // If we didn't leak any resizing out to the root, we don't have to transition
        // the root itself. This means that we can now safely cancel any cancellations
        // that bubbled all the way up.
        const cancelableChildren = viewTransitionCancelableChildren;
        if (cancelableChildren !== null) {
          for (let i = 0; i < cancelableChildren.length; i += 3) {
            cancelViewTransitionName(
              ((cancelableChildren[i]: any): Instance),
              ((cancelableChildren[i + 1]: any): string),
              ((cancelableChildren[i + 2]: any): Props),
            );
          }
        }
        // We also cancel the root itself.
        cancelRootViewTransitionName(root.containerInfo);
        rootViewTransitionNameCanceled = true;
      }
      popViewTransitionCancelableScope(null);
      break;
    }
    case HostComponent: {
      recursivelyTraverseAfterMutationEffects(root, finishedWork, lanes);
      break;
    }
    case HostPortal: {
      const prevContextChanged = viewTransitionContextChanged;
      viewTransitionContextChanged = false;
      recursivelyTraverseAfterMutationEffects(root, finishedWork, lanes);
      if (viewTransitionContextChanged) {
        // A Portal doesn't necessarily exist within the context of this subtree.
        // Ideally we would track which React ViewTransition component nests the container
        // but that's costly. Instead, we treat each Portal as if it's a new React root.
        // Therefore any leaked resize of a child could affect the root so the root should animate.
        // We only do this if the Portal is inside a ViewTransition and it is not disabled
        // with update="none". Otherwise the Portal is considered not animating.
        rootViewTransitionAffected = true;
      }
      viewTransitionContextChanged = prevContextChanged;
      break;
    }
    case OffscreenComponent: {
      const isModernRoot =
        disableLegacyMode || (finishedWork.mode & ConcurrentMode) !== NoMode;
      if (isModernRoot) {
        const isHidden = finishedWork.memoizedState !== null;
        if (isHidden) {
          // The Offscreen tree is hidden. Skip over its after mutation effects.
        } else {
          // The Offscreen tree is visible.
          const wasHidden = current.memoizedState !== null;
          if (wasHidden) {
            commitEnterViewTransitions(finishedWork, false);
            // If it was previous hidden then the children are treated as enter
            // not updates so we don't need to visit these children.
          } else {
            recursivelyTraverseAfterMutationEffects(root, finishedWork, lanes);

Domain

Subdomains

Frequently Asked Questions

What does commitAfterMutationEffectsOnFiber() do?
commitAfterMutationEffectsOnFiber() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberCommitWork.js.
Where is commitAfterMutationEffectsOnFiber() defined?
commitAfterMutationEffectsOnFiber() is defined in packages/react-reconciler/src/ReactFiberCommitWork.js at line 2805.
What does commitAfterMutationEffectsOnFiber() call?
commitAfterMutationEffectsOnFiber() calls 1 function(s): recursivelyTraverseAfterMutationEffects.
What calls commitAfterMutationEffectsOnFiber()?
commitAfterMutationEffectsOnFiber() is called by 2 function(s): commitAfterMutationEffects, recursivelyTraverseAfterMutationEffects.

Analyze Your Own Codebase

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

Try Supermodel Free