Skip to content

Commit 951a292

Browse files
committed
Fix: Passive effect updates are never sync
I screwed this up in facebook#21082. Got confused by the < versus > thing again. The helper functions are annoying, too, because I always forget the intended order of the arguments. But they're still helpful because when we refactor the type we only have the change the logic in one place. Added a regression test.
1 parent 03ede83 commit 951a292

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

packages/react-reconciler/src/ReactEventPriorities.new.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ export function higherEventPriority(
5353
return a !== 0 && a < b ? a : b;
5454
}
5555

56+
export function lowerEventPriority(
57+
a: EventPriority,
58+
b: EventPriority,
59+
): EventPriority {
60+
return a === 0 || a > b ? a : b;
61+
}
62+
5663
export function isHigherEventPriority(
5764
a: EventPriority,
5865
b: EventPriority,

packages/react-reconciler/src/ReactEventPriorities.old.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ export function higherEventPriority(
5353
return a !== 0 && a < b ? a : b;
5454
}
5555

56+
export function lowerEventPriority(
57+
a: EventPriority,
58+
b: EventPriority,
59+
): EventPriority {
60+
return a === 0 || a > b ? a : b;
61+
}
62+
5663
export function isHigherEventPriority(
5764
a: EventPriority,
5865
b: EventPriority,

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ import {
163163
DefaultEventPriority,
164164
getCurrentUpdatePriority,
165165
setCurrentUpdatePriority,
166-
higherEventPriority,
166+
lowerEventPriority,
167167
lanesToEventPriority,
168168
} from './ReactEventPriorities.new';
169169
import {requestCurrentTransition, NoTransition} from './ReactFiberTransition';
@@ -2008,10 +2008,8 @@ function commitRootImpl(root, renderPriorityLevel) {
20082008
export function flushPassiveEffects(): boolean {
20092009
// Returns whether passive effects were flushed.
20102010
if (pendingPassiveEffectsLanes !== NoLanes) {
2011-
const priority = higherEventPriority(
2012-
DefaultEventPriority,
2013-
lanesToEventPriority(pendingPassiveEffectsLanes),
2014-
);
2011+
const renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes);
2012+
const priority = lowerEventPriority(DefaultEventPriority, renderPriority);
20152013
const previousPriority = getCurrentUpdatePriority();
20162014
try {
20172015
setCurrentUpdatePriority(priority);

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ import {
163163
DefaultEventPriority,
164164
getCurrentUpdatePriority,
165165
setCurrentUpdatePriority,
166-
higherEventPriority,
166+
lowerEventPriority,
167167
lanesToEventPriority,
168168
} from './ReactEventPriorities.old';
169169
import {requestCurrentTransition, NoTransition} from './ReactFiberTransition';
@@ -2008,10 +2008,8 @@ function commitRootImpl(root, renderPriorityLevel) {
20082008
export function flushPassiveEffects(): boolean {
20092009
// Returns whether passive effects were flushed.
20102010
if (pendingPassiveEffectsLanes !== NoLanes) {
2011-
const priority = higherEventPriority(
2012-
DefaultEventPriority,
2013-
lanesToEventPriority(pendingPassiveEffectsLanes),
2014-
);
2011+
const renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes);
2012+
const priority = lowerEventPriority(DefaultEventPriority, renderPriority);
20152013
const previousPriority = getCurrentUpdatePriority();
20162014
try {
20172015
setCurrentUpdatePriority(priority);

0 commit comments

Comments
 (0)