Skip to content

Commit 0fd6805

Browse files
authored
Land rest of effects refactor in main fork (#20644)
1 parent a6b5256 commit 0fd6805

11 files changed

+234
-392
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ module.exports = {
116116
'react-internal/no-cross-fork-types': [
117117
ERROR,
118118
{
119-
old: ['firstEffect', 'nextEffect'],
119+
old: [],
120120
new: [],
121121
},
122122
],

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

+1-21
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ import type {Fiber} from './ReactInternalTypes';
1313
import type {Lanes} from './ReactFiberLane.old';
1414

1515
import getComponentName from 'shared/getComponentName';
16-
import {
17-
Deletion,
18-
ChildDeletion,
19-
Placement,
20-
StaticMask,
21-
} from './ReactFiberFlags';
16+
import {Placement, ChildDeletion} from './ReactFiberFlags';
2217
import {
2318
getIteratorFn,
2419
REACT_ELEMENT_TYPE,
@@ -268,21 +263,6 @@ function ChildReconciler(shouldTrackSideEffects) {
268263
// Noop.
269264
return;
270265
}
271-
// Deletions are added in reversed order so we add it to the front.
272-
// At this point, the return fiber's effect list is empty except for
273-
// deletions, so we can just append the deletion to the list. The remaining
274-
// effects aren't added until the complete phase. Once we implement
275-
// resuming, this may not be true.
276-
const last = returnFiber.lastEffect;
277-
if (last !== null) {
278-
last.nextEffect = childToDelete;
279-
returnFiber.lastEffect = childToDelete;
280-
} else {
281-
returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
282-
}
283-
childToDelete.nextEffect = null;
284-
childToDelete.flags = (childToDelete.flags & StaticMask) | Deletion;
285-
286266
const deletions = returnFiber.deletions;
287267
if (deletions === null) {
288268
returnFiber.deletions = [childToDelete];

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

+5-15
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ function FiberNode(
144144

145145
// Effects
146146
this.flags = NoFlags;
147-
this.nextEffect = null;
148-
149-
this.firstEffect = null;
150-
this.lastEffect = null;
151147
this.subtreeFlags = NoFlags;
152148
this.deletions = null;
153149

@@ -285,10 +281,7 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
285281
// Reset the effect tag.
286282
workInProgress.flags = NoFlags;
287283

288-
// The effect list is no longer valid.
289-
workInProgress.nextEffect = null;
290-
workInProgress.firstEffect = null;
291-
workInProgress.lastEffect = null;
284+
// The effects are no longer valid.
292285
workInProgress.subtreeFlags = NoFlags;
293286
workInProgress.deletions = null;
294287

@@ -370,10 +363,7 @@ export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
370363
// that child fiber is setting, not the reconciliation.
371364
workInProgress.flags &= StaticMask | Placement;
372365

373-
// The effect list is no longer valid.
374-
workInProgress.nextEffect = null;
375-
workInProgress.firstEffect = null;
376-
workInProgress.lastEffect = null;
366+
// The effects are no longer valid.
377367

378368
const current = workInProgress.alternate;
379369
if (current === null) {
@@ -403,6 +393,9 @@ export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
403393
workInProgress.lanes = current.lanes;
404394

405395
workInProgress.child = current.child;
396+
// TODO: `subtreeFlags` should be reset to NoFlags, like we do in
397+
// `createWorkInProgress`. Nothing reads this until the complete phase,
398+
// currently, but it might in the future, and we should be consistent.
406399
workInProgress.subtreeFlags = current.subtreeFlags;
407400
workInProgress.deletions = null;
408401
workInProgress.memoizedProps = current.memoizedProps;
@@ -847,9 +840,6 @@ export function assignFiberPropertiesInDEV(
847840
target.dependencies = source.dependencies;
848841
target.mode = source.mode;
849842
target.flags = source.flags;
850-
target.nextEffect = source.nextEffect;
851-
target.firstEffect = source.firstEffect;
852-
target.lastEffect = source.lastEffect;
853843
target.subtreeFlags = source.subtreeFlags;
854844
target.deletions = source.deletions;
855845
target.lanes = source.lanes;

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

+3-37
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import {
6767
DidCapture,
6868
Update,
6969
Ref,
70-
Deletion,
7170
ChildDeletion,
7271
ForceUpdateForLegacySuspense,
7372
StaticMask,
@@ -2199,10 +2198,6 @@ function updateSuspensePrimaryChildren(
21992198
primaryChildFragment.sibling = null;
22002199
if (currentFallbackChildFragment !== null) {
22012200
// Delete the fallback child fragment
2202-
currentFallbackChildFragment.nextEffect = null;
2203-
currentFallbackChildFragment.flags =
2204-
(currentFallbackChildFragment.flags & StaticMask) | Deletion;
2205-
workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChildFragment;
22062201
const deletions = workInProgress.deletions;
22072202
if (deletions === null) {
22082203
workInProgress.deletions = [currentFallbackChildFragment];
@@ -2264,22 +2259,9 @@ function updateSuspenseFallbackChildren(
22642259
currentPrimaryChildFragment.treeBaseDuration;
22652260
}
22662261

2267-
if (currentFallbackChildFragment !== null) {
2268-
// The fallback fiber was added as a deletion effect during the first
2269-
// pass. However, since we're going to remain on the fallback, we no
2270-
// longer want to delete it. So we need to remove it from the list.
2271-
// Deletions are stored on the same list as effects, and are always added
2272-
// to the front. So we know that the first effect must be the fallback
2273-
// deletion effect, and everything after that is from the primary free.
2274-
const firstPrimaryTreeEffect = currentFallbackChildFragment.nextEffect;
2275-
if (firstPrimaryTreeEffect !== null) {
2276-
workInProgress.firstEffect = firstPrimaryTreeEffect;
2277-
} else {
2278-
// TODO: Reset this somewhere else? Lol legacy mode is so weird.
2279-
workInProgress.firstEffect = workInProgress.lastEffect = null;
2280-
}
2281-
}
2282-
2262+
// The fallback fiber was added as a deletion during the first pass.
2263+
// However, since we're going to remain on the fallback, we no longer want
2264+
// to delete it.
22832265
workInProgress.deletions = null;
22842266
} else {
22852267
primaryChildFragment = createWorkInProgressOffscreenFiber(
@@ -2776,7 +2758,6 @@ function initSuspenseListRenderState(
27762758
tail: null | Fiber,
27772759
lastContentRow: null | Fiber,
27782760
tailMode: SuspenseListTailMode,
2779-
lastEffectBeforeRendering: null | Fiber,
27802761
): void {
27812762
const renderState: null | SuspenseListRenderState =
27822763
workInProgress.memoizedState;
@@ -2788,7 +2769,6 @@ function initSuspenseListRenderState(
27882769
last: lastContentRow,
27892770
tail: tail,
27902771
tailMode: tailMode,
2791-
lastEffect: lastEffectBeforeRendering,
27922772
}: SuspenseListRenderState);
27932773
} else {
27942774
// We can reuse the existing object from previous renders.
@@ -2798,7 +2778,6 @@ function initSuspenseListRenderState(
27982778
renderState.last = lastContentRow;
27992779
renderState.tail = tail;
28002780
renderState.tailMode = tailMode;
2801-
renderState.lastEffect = lastEffectBeforeRendering;
28022781
}
28032782
}
28042783

@@ -2880,7 +2859,6 @@ function updateSuspenseListComponent(
28802859
tail,
28812860
lastContentRow,
28822861
tailMode,
2883-
workInProgress.lastEffect,
28842862
);
28852863
break;
28862864
}
@@ -2912,7 +2890,6 @@ function updateSuspenseListComponent(
29122890
tail,
29132891
null, // last
29142892
tailMode,
2915-
workInProgress.lastEffect,
29162893
);
29172894
break;
29182895
}
@@ -2923,7 +2900,6 @@ function updateSuspenseListComponent(
29232900
null, // tail
29242901
null, // last
29252902
undefined,
2926-
workInProgress.lastEffect,
29272903
);
29282904
break;
29292905
}
@@ -3183,16 +3159,6 @@ function remountFiber(
31833159

31843160
// Delete the old fiber and place the new one.
31853161
// Since the old fiber is disconnected, we have to schedule it manually.
3186-
const last = returnFiber.lastEffect;
3187-
if (last !== null) {
3188-
last.nextEffect = current;
3189-
returnFiber.lastEffect = current;
3190-
} else {
3191-
returnFiber.firstEffect = returnFiber.lastEffect = current;
3192-
}
3193-
current.nextEffect = null;
3194-
current.flags = (current.flags & StaticMask) | Deletion;
3195-
31963162
const deletions = returnFiber.deletions;
31973163
if (deletions === null) {
31983164
returnFiber.deletions = [current];

0 commit comments

Comments
 (0)