Skip to content

Commit 863ee09

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 2139e0b commit 863ee09

File tree

6 files changed

+371
-190
lines changed

6 files changed

+371
-190
lines changed

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

Lines changed: 10 additions & 5 deletions
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,
@@ -269,7 +274,7 @@ function ChildReconciler(shouldTrackSideEffects) {
269274
returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
270275
}
271276
childToDelete.nextEffect = null;
272-
childToDelete.flags = Deletion;
277+
childToDelete.flags = (childToDelete.flags & StaticMask) | Deletion;
273278

274279
let deletions = returnFiber.deletions;
275280
if (deletions === null) {
@@ -353,15 +358,15 @@ function ChildReconciler(shouldTrackSideEffects) {
353358
const oldIndex = current.index;
354359
if (oldIndex < lastPlacedIndex) {
355360
// This is a move.
356-
newFiber.flags = Placement;
361+
newFiber.flags |= Placement;
357362
return lastPlacedIndex;
358363
} else {
359364
// This item can stay in place.
360365
return oldIndex;
361366
}
362367
} else {
363368
// This is an insertion.
364-
newFiber.flags = Placement;
369+
newFiber.flags |= Placement;
365370
return lastPlacedIndex;
366371
}
367372
}
@@ -370,7 +375,7 @@ function ChildReconciler(shouldTrackSideEffects) {
370375
// This is simpler for the single child case. We only need to do a
371376
// placement for inserting new children.
372377
if (shouldTrackSideEffects && newFiber.alternate === null) {
373-
newFiber.flags = Placement;
378+
newFiber.flags |= Placement;
374379
}
375380
return newFiber;
376381
}

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)