function flushPassiveEffects()

in Libraries/Renderer/implementations/ReactFabric-profiling.js [7048:7248]


function flushPassiveEffects() {
  if (null !== rootWithPendingPassiveEffects) {
    var renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes),
      prevTransition = ReactCurrentBatchConfig$2.transition,
      previousPriority = currentUpdatePriority;
    try {
      ReactCurrentBatchConfig$2.transition = 0;
      currentUpdatePriority = 16 > renderPriority ? 16 : renderPriority;
      if (null === rootWithPendingPassiveEffects)
        var JSCompiler_inline_result = !1;
      else {
        renderPriority = rootWithPendingPassiveEffects;
        rootWithPendingPassiveEffects = null;
        pendingPassiveEffectsLanes = 0;
        if (0 !== (executionContext & 24))
          throw Error("Cannot flush passive effects while already rendering.");
        var prevExecutionContext = executionContext;
        executionContext |= 16;
        for (nextEffect = renderPriority.current; null !== nextEffect; ) {
          var fiber = nextEffect,
            child = fiber.child;
          if (0 !== (nextEffect.flags & 16)) {
            var deletions = fiber.deletions;
            if (null !== deletions) {
              for (var i = 0; i < deletions.length; i++) {
                var fiberToDelete = deletions[i];
                for (nextEffect = fiberToDelete; null !== nextEffect; ) {
                  var fiber$jscomp$0 = nextEffect,
                    current = fiber$jscomp$0;
                  switch (current.tag) {
                    case 0:
                    case 11:
                    case 15:
                      current.mode & 2
                        ? ((passiveEffectStartTime = now$1()),
                          commitHookEffectListUnmount(4, current, fiber),
                          recordPassiveEffectDuration(current))
                        : commitHookEffectListUnmount(4, current, fiber);
                  }
                  var child$jscomp$0 = fiber$jscomp$0.child;
                  if (null !== child$jscomp$0)
                    (child$jscomp$0.return = fiber$jscomp$0),
                      (nextEffect = child$jscomp$0);
                  else
                    for (; null !== nextEffect; ) {
                      fiber$jscomp$0 = nextEffect;
                      var sibling = fiber$jscomp$0.sibling,
                        returnFiber = fiber$jscomp$0.return;
                      detachFiberAfterEffects(fiber$jscomp$0);
                      if (fiber$jscomp$0 === fiberToDelete) {
                        nextEffect = null;
                        break;
                      }
                      if (null !== sibling) {
                        sibling.return = returnFiber;
                        nextEffect = sibling;
                        break;
                      }
                      nextEffect = returnFiber;
                    }
                }
              }
              var previousFiber = fiber.alternate;
              if (null !== previousFiber) {
                var detachedChild = previousFiber.child;
                if (null !== detachedChild) {
                  previousFiber.child = null;
                  do {
                    var detachedSibling = detachedChild.sibling;
                    detachedChild.sibling = null;
                    detachedChild = detachedSibling;
                  } while (null !== detachedChild);
                }
              }
              nextEffect = fiber;
            }
          }
          if (0 !== (fiber.subtreeFlags & 1040) && null !== child)
            (child.return = fiber), (nextEffect = child);
          else
            b: for (; null !== nextEffect; ) {
              fiber = nextEffect;
              if (0 !== (fiber.flags & 1024))
                switch (((i = fiber), i.tag)) {
                  case 0:
                  case 11:
                  case 15:
                    i.mode & 2
                      ? ((passiveEffectStartTime = now$1()),
                        commitHookEffectListUnmount(5, i, i.return),
                        recordPassiveEffectDuration(i))
                      : commitHookEffectListUnmount(5, i, i.return);
                }
              var sibling$jscomp$0 = fiber.sibling;
              if (null !== sibling$jscomp$0) {
                sibling$jscomp$0.return = fiber.return;
                nextEffect = sibling$jscomp$0;
                break b;
              }
              nextEffect = fiber.return;
            }
        }
        var finishedWork = renderPriority.current;
        for (nextEffect = finishedWork; null !== nextEffect; ) {
          child = nextEffect;
          var firstChild = child.child;
          if (0 !== (child.subtreeFlags & 1040) && null !== firstChild)
            (firstChild.return = child), (nextEffect = firstChild);
          else
            b: for (child = finishedWork; null !== nextEffect; ) {
              deletions = nextEffect;
              if (0 !== (deletions.flags & 1024))
                try {
                  switch (((fiberToDelete = deletions), fiberToDelete.tag)) {
                    case 0:
                    case 11:
                    case 15:
                      if (fiberToDelete.mode & 2) {
                        passiveEffectStartTime = now$1();
                        try {
                          commitHookEffectListMount(5, fiberToDelete);
                        } finally {
                          recordPassiveEffectDuration(fiberToDelete);
                        }
                      } else commitHookEffectListMount(5, fiberToDelete);
                  }
                } catch (error) {
                  captureCommitPhaseError(deletions, deletions.return, error);
                }
              if (deletions === child) {
                nextEffect = null;
                break b;
              }
              var sibling$jscomp$1 = deletions.sibling;
              if (null !== sibling$jscomp$1) {
                sibling$jscomp$1.return = deletions.return;
                nextEffect = sibling$jscomp$1;
                break b;
              }
              nextEffect = deletions.return;
            }
        }
        finishedWork = pendingPassiveProfilerEffects;
        pendingPassiveProfilerEffects = [];
        for (firstChild = 0; firstChild < finishedWork.length; firstChild++) {
          var finishedWork$jscomp$0 = finishedWork[firstChild];
          if (0 !== (finishedWork$jscomp$0.flags & 4))
            switch (finishedWork$jscomp$0.tag) {
              case 12:
                var passiveEffectDuration =
                    finishedWork$jscomp$0.stateNode.passiveEffectDuration,
                  _finishedWork$memoize = finishedWork$jscomp$0.memoizedProps,
                  id = _finishedWork$memoize.id,
                  onPostCommit = _finishedWork$memoize.onPostCommit;
                sibling$jscomp$1 = commitTime;
                var phase =
                  null === finishedWork$jscomp$0.alternate ? "mount" : "update";
                currentUpdateIsNested && (phase = "nested-update");
                "function" === typeof onPostCommit &&
                  onPostCommit(
                    id,
                    phase,
                    passiveEffectDuration,
                    sibling$jscomp$1
                  );
                var parentFiber = finishedWork$jscomp$0.return;
                b: for (; null !== parentFiber; ) {
                  switch (parentFiber.tag) {
                    case 3:
                      parentFiber.stateNode.passiveEffectDuration += passiveEffectDuration;
                      break b;
                    case 12:
                      parentFiber.stateNode.passiveEffectDuration += passiveEffectDuration;
                      break b;
                  }
                  parentFiber = parentFiber.return;
                }
            }
        }
        executionContext = prevExecutionContext;
        flushSyncCallbacks();
        if (
          injectedHook &&
          "function" === typeof injectedHook.onPostCommitFiberRoot
        )
          try {
            injectedHook.onPostCommitFiberRoot(rendererID, renderPriority);
          } catch (err) {}
        var stateNode = renderPriority.current.stateNode;
        stateNode.effectDuration = 0;
        stateNode.passiveEffectDuration = 0;
        JSCompiler_inline_result = !0;
      }
      return JSCompiler_inline_result;
    } finally {
      (currentUpdatePriority = previousPriority),
        (ReactCurrentBatchConfig$2.transition = prevTransition);
    }
  }
  return !1;
}