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 31, 2020
1 parent 9a38b12 commit 4ead1e9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
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 4ead1e9

Please sign in to comment.