Skip to content

Commit

Permalink
Avoid scheduling unnecessary callbacks for cleanup effects
Browse files Browse the repository at this point in the history
Updated enqueuePendingPassiveEffectDestroyFn() to check rootDoesHavePassiveEffects before scheduling a new callback. This way we'll only schedule (at most) one.
  • Loading branch information
Brian Vaughn committed Jan 30, 2020
1 parent e1ff76a commit 167fcd3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Expand Up @@ -2183,11 +2183,13 @@ export function enqueuePendingPassiveEffectDestroyFn(
): void {
if (deferPassiveEffectCleanupDuringUnmount) {
pendingUnmountedPassiveEffectDestroyFunctions.push(destroy);
rootDoesHavePassiveEffects = true;
scheduleCallback(NormalPriority, () => {
flushPassiveEffects();
return null;
});
if (!rootDoesHavePassiveEffects) {
rootDoesHavePassiveEffects = true;
scheduleCallback(NormalPriority, () => {
flushPassiveEffects();
return null;
});
}
}
}

Expand Down

0 comments on commit 167fcd3

Please sign in to comment.