Repository: facebook/react
File: packages/react-reconciler/src/ReactFiberCommitWork.js (JavaScript)

Code before:
function hideOrUnhideNearestPortals(parentFiber: Fiber, isHidden: boolean) {
  if (!supportsMutation) {
    return;
  }
  if (parentFiber.subtreeFlags & PortalStatic) {
    let child = parentFiber.child;
    while (child !== null) {
      hideOrUnhideNearestPortalsOnFiber(child, isHidden);
      child = child.sibling;
    }
  }
}

function hideOrUnhideNearestPortalsOnFiber(fiber: Fiber, isHidden: boolean) {
  if (!supportsMutation) {
    return;
  }
  switch (fiber.tag) {
    case HostPortal: {
      // Found a portal. Switch back to the normal hide/unhide algorithm to
      // toggle the visibility of its children.
      hideOrUnhideAllChildrenOnFiber(fiber, isHidden);
      return;
    }
    case OffscreenComponent:
    case LegacyHiddenComponent: {
      const activityState: ActivityState | null = fiber.memoizedState;
      if (activityState !== null) {
        // Found a nested Offscreen component that is hidden. Don't search any
        // deeper. This tree should remain hidden.
      } else {
        hideOrUnhideNearestPortals(fiber, isHidden);
      }
      return;
    }
    default: {
      hideOrUnhideNearestPortals(fiber, isHidden);
      return;
    }
  }
}

function detachFiberMutation(fiber: Fiber) {
  // Cut off the return pointer to disconnect it from the tree.
  // This enables us to detect and warn against state updates on an unmounted component.
  // It also prevents events from bubbling from within disconnected components.
  //
  // Ideally, we should also clear the child pointer of the parent alternate to let this
  // get GC:ed but we don't know which for sure which parent is the current
  // one so we'll settle for GC:ing the subtree of this child.
  // This child itself will be GC:ed when the parent updates the next time.

Review comment (suggestion):
Could we omit `LegacyHidden` from this? Want to limit the risk of breaking changes and if they need this feature they should convert to Activity.

Code after:
function hideOrUnhideNearestPortals(parentFiber: Fiber, isHidden: boolean) {
  if (!supportsMutation) {
    return;
  }
  if (parentFiber.subtreeFlags & PortalStatic) {
    let child = parentFiber.child;
    while (child !== null) {
      hideOrUnhideNearestPortalsOnFiber(child, isHidden);
      child = child.sibling;
    }
  }
}

function hideOrUnhideNearestPortalsOnFiber(fiber: Fiber, isHidden: boolean) {
  if (!supportsMutation) {
    return;
  }
  switch (fiber.tag) {
    case HostPortal: {
      // Found a portal. Switch back to the normal hide/unhide algorithm to
      // toggle the visibility of its children.
      hideOrUnhideAllChildrenOnFiber(fiber, isHidden);
      return;
    }
    case OffscreenComponent: {
      const offscreenState: OffscreenState | null = fiber.memoizedState;
      if (offscreenState !== null) {
        // Found a nested Offscreen component that is hidden. Don't search any
        // deeper. This tree should remain hidden.
      } else {
        hideOrUnhideNearestPortals(fiber, isHidden);
      }
      return;
    }
    default: {
      hideOrUnhideNearestPortals(fiber, isHidden);
      return;
    }
  }
}

function detachFiberMutation(fiber: Fiber) {
  // Cut off the return pointer to disconnect it from the tree.
  // This enables us to detect and warn against state updates on an unmounted component.
  // It also prevents events from bubbling from within disconnected components.
  //
  // Ideally, we should also clear the child pointer of the parent alternate to let this
  // get GC:ed but we don't know which for sure which parent is the current
  // one so we'll settle for GC:ing the subtree of this child.
  // This child itself will be GC:ed when the parent updates the next time.
  //