Skip to content

Commit 23cfe22

Browse files
committed
Migrate passive phase to depth first traversal
Because the passive phase happens after paint, I expect it's least likely to cause a performance regression. In terms of implementation complexity, however, it's probably the riskiest. Ideally, for this initial step, we would change nothing except the traversal logic. However, the old implementation is pretty weird; it doesn't really use the effect list in the normal way that the other phases do. Instead, it pushes effects into a pair global arrays (one for mount effects, one for unmount effects) during the layout phase. For those reasons, I think it makes sense to split this phase out into its own step. There's also potential for upside since we're removing code from the layout phase. The other phases are hard to justify migrating one at a time because the overhead of doing a depth-first search while also keeping track of an effect list is larger than if we just migrate them all at once.
1 parent 6403645 commit 23cfe22

6 files changed

Lines changed: 368 additions & 187 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import type {Fiber} from './ReactInternalTypes';
1313
import type {Lanes} from './ReactFiberLane.new';
1414

1515
import getComponentName from 'shared/getComponentName';
16-
import {Deletion, ChildDeletion, Placement} from './ReactFiberFlags';
16+
import {
17+
Deletion,
18+
ChildDeletion,
19+
Placement,
20+
StaticMask,
21+
} from './ReactFiberFlags';
1722
import {
1823
getIteratorFn,
1924
REACT_ELEMENT_TYPE,
@@ -275,7 +280,7 @@ function ChildReconciler(shouldTrackSideEffects) {
275280
returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
276281
}
277282
childToDelete.nextEffect = null;
278-
childToDelete.flags = Deletion;
283+
childToDelete.flags = (childToDelete.flags & StaticMask) | Deletion;
279284

280285
let deletions = returnFiber.deletions;
281286
if (deletions === null) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,8 @@ function updateSuspensePrimaryChildren(
20072007
if (currentFallbackChildFragment !== null) {
20082008
// Delete the fallback child fragment
20092009
currentFallbackChildFragment.nextEffect = null;
2010-
currentFallbackChildFragment.flags = Deletion;
2010+
currentFallbackChildFragment.flags =
2011+
(currentFallbackChildFragment.flags & StaticMask) | Deletion;
20112012
workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChildFragment;
20122013
let deletions = workInProgress.deletions;
20132014
if (deletions === null) {
@@ -2998,7 +2999,7 @@ function remountFiber(
29982999
returnFiber.firstEffect = returnFiber.lastEffect = current;
29993000
}
30003001
current.nextEffect = null;
3001-
current.flags = Deletion;
3002+
current.flags = (current.flags & StaticMask) | Deletion;
30023003

30033004
let deletions = returnFiber.deletions;
30043005
if (deletions === null) {

0 commit comments

Comments
 (0)