Skip to content

Commit 0f4abc9

Browse files
committed
Track Host Mutations in Apply Gesture
Because we don't use the helpers in CommitHostEffects we have to manually track whether this caused any mutations for deletions, insertions, hides, unhides and updates to text content. Otherwise, we end up canceling boundaries that should've animated.
1 parent a3e0ee8 commit 0f4abc9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/react-reconciler/src/ReactFiberApplyGesture.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
popMutationContext,
4141
pushMutationContext,
4242
viewTransitionMutationContext,
43+
trackHostMutation,
4344
} from './ReactFiberMutationTracking';
4445
import {
4546
MutationMask,
@@ -432,6 +433,7 @@ function recursivelyInsertNewFiber(
432433
// For insertions we don't need to clone. It's already new state node.
433434
if (visitPhase !== INSERT_APPEARING_PAIR) {
434435
appendChild(hostParentClone, instance);
436+
trackHostMutation();
435437
recursivelyInsertNew(
436438
finishedWork,
437439
instance,
@@ -461,6 +463,7 @@ function recursivelyInsertNewFiber(
461463
// For insertions we don't need to clone. It's already new state node.
462464
if (visitPhase !== INSERT_APPEARING_PAIR) {
463465
appendChild(hostParentClone, textInstance);
466+
trackHostMutation();
464467
}
465468
break;
466469
}
@@ -586,6 +589,7 @@ function recursivelyInsertClonesFromExistingTree(
586589
}
587590
if (visitPhase === CLONE_EXIT || visitPhase === CLONE_UNHIDE) {
588591
unhideInstance(clone, child.memoizedProps);
592+
trackHostMutation();
589593
}
590594
break;
591595
}
@@ -601,6 +605,7 @@ function recursivelyInsertClonesFromExistingTree(
601605
appendChild(hostParentClone, clone);
602606
if (visitPhase === CLONE_EXIT || visitPhase === CLONE_UNHIDE) {
603607
unhideTextInstance(clone, child.memoizedProps);
608+
trackHostMutation();
604609
}
605610
break;
606611
}
@@ -690,6 +695,10 @@ function recursivelyInsertClones(
690695
for (let i = 0; i < deletions.length; i++) {
691696
const childToDelete = deletions[i];
692697
trackEnterViewTransitions(childToDelete);
698+
// Normally we would only mark something as triggering a mutation if there was
699+
// actually a HostInstance below here. If this tree didn't contain a HostInstances
700+
// we shouldn't trigger a mutation even though a virtual component was deleted.
701+
trackHostMutation();
693702
}
694703
}
695704

@@ -812,6 +821,7 @@ function insertDestinationClonesOfFiber(
812821
clone = cloneMutableInstance(instance, true);
813822
if (finishedWork.flags & ContentReset) {
814823
resetTextContent(clone);
824+
trackHostMutation();
815825
}
816826
} else {
817827
// If we have children we'll clone them as we walk the tree so we just
@@ -836,6 +846,7 @@ function insertDestinationClonesOfFiber(
836846
);
837847
appendChild(hostParentClone, clone);
838848
unhideInstance(clone, finishedWork.memoizedProps);
849+
trackHostMutation();
839850
} else {
840851
recursivelyInsertClones(finishedWork, clone, null, visitPhase);
841852
appendChild(hostParentClone, clone);
@@ -862,10 +873,12 @@ function insertDestinationClonesOfFiber(
862873
const newText: string = finishedWork.memoizedProps;
863874
const oldText: string = current.memoizedProps;
864875
commitTextUpdate(clone, newText, oldText);
876+
trackHostMutation();
865877
}
866878
appendChild(hostParentClone, clone);
867879
if (visitPhase === CLONE_EXIT || visitPhase === CLONE_UNHIDE) {
868880
unhideTextInstance(clone, finishedWork.memoizedProps);
881+
trackHostMutation();
869882
}
870883
break;
871884
}
@@ -896,6 +909,10 @@ function insertDestinationClonesOfFiber(
896909
} else if (current !== null && current.memoizedState === null) {
897910
// Was previously mounted as visible but is now hidden.
898911
trackEnterViewTransitions(current);
912+
// Normally we would only mark something as triggering a mutation if there was
913+
// actually a HostInstance below here. If this tree didn't contain a HostInstances
914+
// we shouldn't trigger a mutation even though a virtual component was hidden.
915+
trackHostMutation();
899916
}
900917
break;
901918
}

packages/react-reconciler/src/ReactFiberCommitHostEffects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export function commitShowHideHostTextInstance(node: Fiber, isHidden: boolean) {
199199
unhideTextInstance(instance, node.memoizedProps);
200200
}
201201
}
202+
trackHostMutation();
202203
} catch (error) {
203204
captureCommitPhaseError(node, node.return, error);
204205
}

0 commit comments

Comments
 (0)