From 13411e4589f3d999727c5322781e2dd7bef3b256 Mon Sep 17 00:00:00 2001 From: Jack Pope Date: Mon, 14 Oct 2024 14:12:23 -0400 Subject: [PATCH] [Re-land] Make prerendering always non-blocking: Add missing feature flag checks (#31238) This is a partial re-land of https://github.com/facebook/react/pull/31056. We saw breakages surface after the original land and had to revert. Now that they've been fixed, let's try this again. This time we'll split up the commits to give us more control of testing and rollout internally. Original PR: https://github.com/facebook/react/pull/31056 Original Commit: https://github.com/facebook/react/pull/31056/commits/2a9fb445d98b60a97f3642cec2ff22469727e0c7 Revert PR: https://github.com/facebook/react/pull/31080 Commit description: ``` Neglected to wrap some places in the enableSiblingPrerendering flag. ``` Co-authored-by: Andrew Clark --- .../src/ReactFiberCompleteWork.js | 5 +++- .../react-reconciler/src/ReactFiberLane.js | 28 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.js b/packages/react-reconciler/src/ReactFiberCompleteWork.js index e3fba900dd116..b24351ac383b9 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.js @@ -42,6 +42,7 @@ import { enableRenderableContext, passChildrenWhenCloningPersistedNodes, disableLegacyMode, + enableSiblingPrerendering, } from 'shared/ReactFeatureFlags'; import {now} from './Scheduler'; @@ -622,7 +623,9 @@ function scheduleRetryEffect( // Track the lanes that have been scheduled for an immediate retry so that // we can mark them as suspended upon committing the root. - markSpawnedRetryLane(retryLane); + if (enableSiblingPrerendering) { + markSpawnedRetryLane(retryLane); + } } } diff --git a/packages/react-reconciler/src/ReactFiberLane.js b/packages/react-reconciler/src/ReactFiberLane.js index b8c051def4eef..7d6bfd16e8aa0 100644 --- a/packages/react-reconciler/src/ReactFiberLane.js +++ b/packages/react-reconciler/src/ReactFiberLane.js @@ -27,6 +27,7 @@ import { transitionLaneExpirationMs, retryLaneExpirationMs, disableLegacyMode, + enableSiblingPrerendering, } from 'shared/ReactFeatureFlags'; import {isDevToolsPresent} from './ReactFiberDevToolsHook'; import {clz32} from './clz32'; @@ -270,11 +271,13 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes { if (nonIdlePingedLanes !== NoLanes) { nextLanes = getHighestPriorityLanes(nonIdlePingedLanes); } else { - // Nothing has been pinged. Check for lanes that need to be prewarmed. - if (!rootHasPendingCommit) { - const lanesToPrewarm = nonIdlePendingLanes & ~warmLanes; - if (lanesToPrewarm !== NoLanes) { - nextLanes = getHighestPriorityLanes(lanesToPrewarm); + if (enableSiblingPrerendering) { + // Nothing has been pinged. Check for lanes that need to be prewarmed. + if (!rootHasPendingCommit) { + const lanesToPrewarm = nonIdlePendingLanes & ~warmLanes; + if (lanesToPrewarm !== NoLanes) { + nextLanes = getHighestPriorityLanes(lanesToPrewarm); + } } } } @@ -294,11 +297,13 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes { if (pingedLanes !== NoLanes) { nextLanes = getHighestPriorityLanes(pingedLanes); } else { - // Nothing has been pinged. Check for lanes that need to be prewarmed. - if (!rootHasPendingCommit) { - const lanesToPrewarm = pendingLanes & ~warmLanes; - if (lanesToPrewarm !== NoLanes) { - nextLanes = getHighestPriorityLanes(lanesToPrewarm); + if (enableSiblingPrerendering) { + // Nothing has been pinged. Check for lanes that need to be prewarmed. + if (!rootHasPendingCommit) { + const lanesToPrewarm = pendingLanes & ~warmLanes; + if (lanesToPrewarm !== NoLanes) { + nextLanes = getHighestPriorityLanes(lanesToPrewarm); + } } } } @@ -765,7 +770,7 @@ export function markRootSuspended( root.suspendedLanes |= suspendedLanes; root.pingedLanes &= ~suspendedLanes; - if (!didSkipSuspendedSiblings) { + if (enableSiblingPrerendering && !didSkipSuspendedSiblings) { // Mark these lanes as warm so we know there's nothing else to work on. root.warmLanes |= suspendedLanes; } else { @@ -876,6 +881,7 @@ export function markRootFinished( // suspended) instead of the regular mode (i.e. unwind and skip the siblings // as soon as something suspends to unblock the rest of the update). if ( + enableSiblingPrerendering && suspendedRetryLanes !== NoLanes && // Note that we only do this if there were no updates since we started // rendering. This mirrors the logic in markRootUpdated — whenever we