Add early exit to strict mode (#25235)
Samuel Susla committed
Sep 13, 2022 at 12:08 UTC
e52fa4c575e92b27d5d453829c7110bc5193f7a0
2 files changed
+10
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+5
@@ -3172,6 +3172,11 @@ function recursivelyTraverseAndDoubleInvokeEffectsInDEV(
3172
parentFiber: Fiber,
3173
isInStrictMode: boolean,
3174
) {
3175
+ if ((parentFiber.subtreeFlags & (PlacementDEV | Visibility)) === NoFlags) {
3176
+ // Parent's descendants have already had effects double invoked.
3177
+ // Early exit to avoid unnecessary tree traversal.
3178
+ return;
3179
+ }
3180
let child = parentFiber.child;
3181
while (child !== null) {
3182
doubleInvokeEffectsInDEV(root, child, isInStrictMode);
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+5
@@ -3172,6 +3172,11 @@ function recursivelyTraverseAndDoubleInvokeEffectsInDEV(
3172
parentFiber: Fiber,
3173
isInStrictMode: boolean,
3174
) {
3175
+ if ((parentFiber.subtreeFlags & (PlacementDEV | Visibility)) === NoFlags) {
3176
+ // Parent's descendants have already had effects double invoked.
3177
+ // Early exit to avoid unnecessary tree traversal.
3178
+ return;
3179
+ }
3180
let child = parentFiber.child;
3181
while (child !== null) {
3182
doubleInvokeEffectsInDEV(root, child, isInStrictMode);