@samitouri / QOS-React-2 / commits / 1377e465dd

Add Placement bit without removing others (#20398)

When scheduling a Placement effect, we should add the Placement bit without resetting the others. In the old fork, there are no flags to reset, anyway, since by the time we reach the child reconciler, the flags will have already been reset. However, in the effects refactor, "static" flags are not reset, so this can actually manifest as a bug. See #20285 for a regression test.

Andrew Clark committed Dec 7, 2020 at 15:07 UTC 1377e465ddc492a1b4b33d75e652bce9b273cc85
2 files changed +6 -6
packages/react-reconciler/src/ReactChildFiber.new.js
+3 -3
@@ -342,7 +342,7 @@ function ChildReconciler(shouldTrackSideEffects) {
342 const oldIndex = current.index;
343 if (oldIndex < lastPlacedIndex) {
344 // This is a move.
345 - newFiber.flags = Placement;
345 + newFiber.flags |= Placement;
346 return lastPlacedIndex;
347 } else {
348 // This item can stay in place.
@@ -350,7 +350,7 @@ function ChildReconciler(shouldTrackSideEffects) {
350 }
351 } else {
352 // This is an insertion.
353 - newFiber.flags = Placement;
353 + newFiber.flags |= Placement;
354 return lastPlacedIndex;
355 }
356 }
@@ -359,7 +359,7 @@ function ChildReconciler(shouldTrackSideEffects) {
359 // This is simpler for the single child case. We only need to do a
360 // placement for inserting new children.
361 if (shouldTrackSideEffects && newFiber.alternate === null) {
362 - newFiber.flags = Placement;
362 + newFiber.flags |= Placement;
363 }
364 return newFiber;
365 }
packages/react-reconciler/src/ReactChildFiber.old.js
+3 -3
@@ -342,7 +342,7 @@ function ChildReconciler(shouldTrackSideEffects) {
342 const oldIndex = current.index;
343 if (oldIndex < lastPlacedIndex) {
344 // This is a move.
345 - newFiber.flags = Placement;
345 + newFiber.flags |= Placement;
346 return lastPlacedIndex;
347 } else {
348 // This item can stay in place.
@@ -350,7 +350,7 @@ function ChildReconciler(shouldTrackSideEffects) {
350 }
351 } else {
352 // This is an insertion.
353 - newFiber.flags = Placement;
353 + newFiber.flags |= Placement;
354 return lastPlacedIndex;
355 }
356 }
@@ -359,7 +359,7 @@ function ChildReconciler(shouldTrackSideEffects) {
359 // This is simpler for the single child case. We only need to do a
360 // placement for inserting new children.
361 if (shouldTrackSideEffects && newFiber.alternate === null) {
362 - newFiber.flags = Placement;
362 + newFiber.flags |= Placement;
363 }
364 return newFiber;
365 }