diff --git a/packages/react-reconciler/src/ReactFiberConcurrentUpdates.js b/packages/react-reconciler/src/ReactFiberConcurrentUpdates.js index 05aeb3cfbb37..f8c67a1c3fed 100644 --- a/packages/react-reconciler/src/ReactFiberConcurrentUpdates.js +++ b/packages/react-reconciler/src/ReactFiberConcurrentUpdates.js @@ -254,7 +254,7 @@ function getRootForUpdatedFiber(sourceFiber: Fiber): FiberRoot | null { // current behavior we've used for several release cycles. Consider not // performing this check if the updated fiber already unmounted, since it's // not possible for that to cause an infinite update loop. - throwIfInfiniteUpdateLoopDetected(); + throwIfInfiniteUpdateLoopDetected(false); // When a setState happens, we must ensure the root is scheduled. Because // update queues do not have a backpointer to the root, the only way to do diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.js b/packages/react-reconciler/src/ReactFiberWorkLoop.js index 9a3953c1b5a2..d1153a201dfc 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.js @@ -1754,7 +1754,7 @@ function markRootUpdated(root: FiberRoot, updatedLanes: Lanes) { didIncludeCommitPhaseUpdate = true; } - throwIfInfiniteUpdateLoopDetected(); + throwIfInfiniteUpdateLoopDetected(true); } } @@ -1773,7 +1773,7 @@ function markRootPinged(root: FiberRoot, pingedLanes: Lanes) { didIncludeCommitPhaseUpdate = true; } - throwIfInfiniteUpdateLoopDetected(); + throwIfInfiniteUpdateLoopDetected(true); } } @@ -5175,7 +5175,9 @@ export function resolveRetryWakeable(boundaryFiber: Fiber, wakeable: Wakeable) { retryTimedOutBoundary(boundaryFiber, retryLane); } -export function throwIfInfiniteUpdateLoopDetected() { +export function throwIfInfiniteUpdateLoopDetected( + isFromInfiniteRenderLoopDetectionInstrumentation: boolean, +) { if (nestedUpdateCount > NESTED_UPDATE_LIMIT) { nestedUpdateCount = 0; nestedPassiveUpdateCount = 0; @@ -5187,7 +5189,10 @@ export function throwIfInfiniteUpdateLoopDetected() { if (enableInfiniteRenderLoopDetection) { if (updateKind === NESTED_UPDATE_SYNC_LANE) { - if (executionContext & RenderContext && workInProgressRoot !== null) { + if ( + isFromInfiniteRenderLoopDetectionInstrumentation || + (executionContext & RenderContext && workInProgressRoot !== null) + ) { // This loop was identified only because of the instrumentation gated with enableInfiniteRenderLoopDetection, warn instead of throwing. if (__DEV__) { console.error(