diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index 5e9edf7945653..fa2e8bd3ecf90 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -3172,6 +3172,11 @@ function recursivelyTraverseAndDoubleInvokeEffectsInDEV( parentFiber: Fiber, isInStrictMode: boolean, ) { + if ((parentFiber.subtreeFlags & (PlacementDEV | Visibility)) === NoFlags) { + // Parent's descendants have already had effects double invoked. + // Early exit to avoid unnecessary tree traversal. + return; + } let child = parentFiber.child; while (child !== null) { doubleInvokeEffectsInDEV(root, child, isInStrictMode); diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index d8a0bc883f4d7..57880c15e502f 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -3172,6 +3172,11 @@ function recursivelyTraverseAndDoubleInvokeEffectsInDEV( parentFiber: Fiber, isInStrictMode: boolean, ) { + if ((parentFiber.subtreeFlags & (PlacementDEV | Visibility)) === NoFlags) { + // Parent's descendants have already had effects double invoked. + // Early exit to avoid unnecessary tree traversal. + return; + } let child = parentFiber.child; while (child !== null) { doubleInvokeEffectsInDEV(root, child, isInStrictMode);