Skip to content

Commit 830f58f

Browse files
committed
gate new code
1 parent 9ad9136 commit 830f58f

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ describe('ReactFabric', () => {
273273
expect(nativeFabricUIManager.completeRoot).toBeCalled();
274274
});
275275

276+
// @gate enablePersistedModeClonedFlag
276277
it('should not clone nodes when layout effects are used', async () => {
277278
const View = createReactNativeComponentClass('RCTView', () => ({
278279
validAttributes: {foo: true},

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import type {
4242
import {
4343
alwaysThrottleDisappearingFallbacks,
4444
enableCreateEventHandleAPI,
45+
enablePersistedModeClonedFlag,
4546
enableProfilerTimer,
4647
enableProfilerCommitHooks,
4748
enableProfilerNestedUpdatePhase,
@@ -2508,7 +2509,10 @@ function recursivelyTraverseMutationEffects(
25082509
}
25092510

25102511
const prevDebugFiber = getCurrentDebugFiberInDEV();
2511-
if (parentFiber.subtreeFlags & (MutationMask | Cloned)) {
2512+
if (
2513+
parentFiber.subtreeFlags &
2514+
(enablePersistedModeClonedFlag ? MutationMask | Cloned : MutationMask)
2515+
) {
25122516
let child = parentFiber.child;
25132517
while (child !== null) {
25142518
setCurrentDebugFiberInDEV(child);

packages/react-reconciler/src/ReactFiberCompleteWork.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
enableLegacyHidden,
3636
enableSuspenseCallback,
3737
enableScopeAPI,
38+
enablePersistedModeClonedFlag,
3839
enableProfilerTimer,
3940
enableCache,
4041
enableTransitionTracing,
@@ -83,6 +84,7 @@ import {
8384
Snapshot,
8485
ChildDeletion,
8586
StaticMask,
87+
MutationMask,
8688
Passive,
8789
ForceClientRender,
8890
MaySuspendCommit,
@@ -187,7 +189,7 @@ function markUpdate(workInProgress: Fiber) {
187189
* it received an update that requires a clone of the tree above.
188190
*/
189191
function markCloned(workInProgress: Fiber) {
190-
if (supportsPersistence) {
192+
if (supportsPersistence && enablePersistedModeClonedFlag) {
191193
workInProgress.flags |= Cloned;
192194
}
193195
}
@@ -209,9 +211,12 @@ function doesRequireClone(current: null | Fiber, completedWork: Fiber) {
209211
// then we only have to check the `completedWork.subtreeFlags`.
210212
let child = completedWork.child;
211213
while (child !== null) {
214+
const checkedFlags = enablePersistedModeClonedFlag
215+
? Cloned | Visibility | Placement
216+
: MutationMask;
212217
if (
213-
(child.flags & (Cloned | Visibility | Placement)) !== NoFlags ||
214-
(child.subtreeFlags & (Cloned | Visibility | Placement)) !== NoFlags
218+
(child.flags & checkedFlags) !== NoFlags ||
219+
(child.subtreeFlags & checkedFlags) !== NoFlags
215220
) {
216221
return true;
217222
}
@@ -498,7 +503,14 @@ function updateHostComponent(
498503
markUpdate(workInProgress);
499504
}
500505
workInProgress.stateNode = newInstance;
501-
if (requiresClone && !passChildrenWhenCloningPersistedNodes) {
506+
if (!requiresClone) {
507+
if (!enablePersistedModeClonedFlag) {
508+
// If there are no other effects in this tree, we need to flag this node as having one.
509+
// Even though we're not going to use it for anything.
510+
// Otherwise parents won't know that there are new children to propagate upwards.
511+
markUpdate(workInProgress);
512+
}
513+
} else if (!passChildrenWhenCloningPersistedNodes) {
502514
// If children have changed, we have to add them all to the set.
503515
appendAllChildren(
504516
newInstance,
@@ -665,6 +677,11 @@ function updateHostText(
665677
currentHostContext,
666678
workInProgress,
667679
);
680+
if (!enablePersistedModeClonedFlag) {
681+
// We'll have to mark it as having an effect, even though we won't use the effect for anything.
682+
// This lets the parents know that at least one of their children has changed.
683+
markUpdate(workInProgress);
684+
}
668685
} else {
669686
workInProgress.stateNode = current.stateNode;
670687
}

0 commit comments

Comments
 (0)