Skip to content

Commit 16563e1

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 9cd7009 commit 16563e1

6 files changed

+371
-190
lines changed

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import type {Fiber} from './ReactInternalTypes';
1313
import type {Lanes} from './ReactFiberLane';
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) {
@@ -359,15 +364,15 @@ function ChildReconciler(shouldTrackSideEffects) {
359364
const oldIndex = current.index;
360365
if (oldIndex < lastPlacedIndex) {
361366
// This is a move.
362-
newFiber.flags = Placement;
367+
newFiber.flags |= Placement;
363368
return lastPlacedIndex;
364369
} else {
365370
// This item can stay in place.
366371
return oldIndex;
367372
}
368373
} else {
369374
// This is an insertion.
370-
newFiber.flags = Placement;
375+
newFiber.flags |= Placement;
371376
return lastPlacedIndex;
372377
}
373378
}
@@ -376,7 +381,7 @@ function ChildReconciler(shouldTrackSideEffects) {
376381
// This is simpler for the single child case. We only need to do a
377382
// placement for inserting new children.
378383
if (shouldTrackSideEffects && newFiber.alternate === null) {
379-
newFiber.flags = Placement;
384+
newFiber.flags |= Placement;
380385
}
381386
return newFiber;
382387
}

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

+3-2
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)