function commitMutationEffects()

in Libraries/Renderer/implementations/ReactFabric-profiling.js [5879:6034]


function commitMutationEffects(root, firstChild, committedLanes) {
  inProgressLanes = committedLanes;
  inProgressRoot = root;
  for (nextEffect = firstChild; null !== nextEffect; ) {
    root = nextEffect;
    firstChild = root.deletions;
    if (null !== firstChild)
      for (
        committedLanes = 0;
        committedLanes < firstChild.length;
        committedLanes++
      ) {
        var childToDelete = firstChild[committedLanes];
        try {
          a: for (var node = childToDelete; ; ) {
            var current = node;
            if (
              injectedHook &&
              "function" === typeof injectedHook.onCommitFiberUnmount
            )
              try {
                injectedHook.onCommitFiberUnmount(rendererID, current);
              } catch (err) {}
            switch (current.tag) {
              case 0:
              case 11:
              case 14:
              case 15:
                var updateQueue = current.updateQueue;
                if (null !== updateQueue) {
                  var lastEffect = updateQueue.lastEffect;
                  if (null !== lastEffect) {
                    var firstEffect = lastEffect.next,
                      effect = firstEffect;
                    do {
                      var _effect = effect,
                        destroy = _effect.destroy,
                        tag = _effect.tag;
                      void 0 !== destroy &&
                        0 !== (tag & 2) &&
                        (current.mode & 2
                          ? (startLayoutEffectTimer(),
                            safelyCallDestroy(current, root, destroy),
                            recordLayoutEffectDuration(current))
                          : safelyCallDestroy(current, root, destroy));
                      effect = effect.next;
                    } while (effect !== firstEffect);
                  }
                }
                break;
              case 1:
                safelyDetachRef(current, root);
                var instance = current.stateNode;
                if ("function" === typeof instance.componentWillUnmount)
                  try {
                    if (
                      ((effect = current),
                      (_effect = instance),
                      (_effect.props = effect.memoizedProps),
                      (_effect.state = effect.memoizedState),
                      effect.mode & 2)
                    )
                      try {
                        startLayoutEffectTimer(),
                          _effect.componentWillUnmount();
                      } finally {
                        recordLayoutEffectDuration(effect);
                      }
                    else _effect.componentWillUnmount();
                  } catch (unmountError) {
                    captureCommitPhaseError(current, root, unmountError);
                  }
                break;
              case 5:
                safelyDetachRef(current, root);
                break;
              case 4:
                createChildNodeSet(current.stateNode.containerInfo);
            }
            if (null !== node.child)
              (node.child.return = node), (node = node.child);
            else {
              if (node === childToDelete) break;
              for (; null === node.sibling; ) {
                if (null === node.return || node.return === childToDelete)
                  break a;
                node = node.return;
              }
              node.sibling.return = node.return;
              node = node.sibling;
            }
          }
          var alternate = childToDelete.alternate;
          null !== alternate && (alternate.return = null);
          childToDelete.return = null;
        } catch (error) {
          captureCommitPhaseError(childToDelete, root, error);
        }
      }
    firstChild = root.child;
    if (0 !== (root.subtreeFlags & 6454) && null !== firstChild)
      (firstChild.return = root), (nextEffect = firstChild);
    else
      for (; null !== nextEffect; ) {
        root = nextEffect;
        try {
          var flags = root.flags;
          if (flags & 256) {
            var current$jscomp$0 = root.alternate;
            if (null !== current$jscomp$0) {
              firstChild = current$jscomp$0;
              var currentRef = firstChild.ref;
              if (null !== currentRef)
                if ("function" === typeof currentRef)
                  if (firstChild.mode & 2)
                    try {
                      startLayoutEffectTimer(), currentRef(null);
                    } finally {
                      recordLayoutEffectDuration(firstChild);
                    }
                  else currentRef(null);
                else currentRef.current = null;
            }
          }
          switch (flags & 2054) {
            case 2:
              root.flags &= -3;
              break;
            case 6:
              root.flags &= -3;
              commitWork(root.alternate, root);
              break;
            case 2048:
              root.flags &= -2049;
              break;
            case 2052:
              root.flags &= -2049;
              commitWork(root.alternate, root);
              break;
            case 4:
              commitWork(root.alternate, root);
          }
        } catch (error) {
          captureCommitPhaseError(root, root.return, error);
        }
        firstChild = root.sibling;
        if (null !== firstChild) {
          firstChild.return = root.return;
          nextEffect = firstChild;
          break;
        }
        nextEffect = root.return;
      }
  }
  inProgressRoot = inProgressLanes = null;
}