Clear Update flag for unchanged trees in the beginning of the commit phase (#32849)
We use the Update flag to track if a View Transition had any mutations or relayout. Unlike the other usage of it, this is just temporary state during the commit phase. Normally the flags gets used in the render phase and we reset it when we rerender but in the case of "nested" updates, those trees didn't update. We're only looking for relayouts. So we need to manually reset it before we start using it. We probably shouldn't abuse the Update flag for this and instead use something like temporary state on ViewTransitionState.
Sebastian Markbåge committed
Apr 11, 2025 at 10:54 UTC
1d6c8168db1d82713202e842df3167787ffa00ed
2 files changed
+12
packages/react-reconciler/src/ReactFiberApplyGesture.js
+6
@@ -631,6 +631,12 @@ function recursivelyInsertClonesFromExistingTree(
631
const viewTransitionState: ViewTransitionState = child.stateNode;
632
// TODO: If this was already cloned by a previous pass we can reuse those clones.
633
viewTransitionState.clones = null;
634
+ // "Existing" view transitions are in subtrees that didn't update so
635
+ // this is a "current". We normally clear this upon rerendering
636
+ // but we use this flag to track changes from layout in the commit.
637
+ // So we need it to be cleared before we do that.
638
+ // TODO: Use some other temporary state to track this.
639
+ child.flags &= ~Update;
640
let nextPhase;
641
if (visitPhase === CLONE_EXIT) {
642
// This was an Enter of a ViewTransition. We now move onto unhiding the inner
packages/react-reconciler/src/ReactFiberCommitViewTransitions.js
+6
@@ -510,6 +510,12 @@ export function commitNestedViewTransitions(changedParent: Fiber): void {
510
props.default,
511
props.update,
512
);
513
+ // "Nested" view transitions are in subtrees that didn't update so
514
+ // this is a "current". We normally clear this upon rerendering
515
+ // but we use this flag to track changes from layout in the commit.
516
+ // So we need it to be cleared before we do that.
517
+ // TODO: Use some other temporary state to track this.
518
+ child.flags &= ~Update;
519
if (className !== 'none') {
520
applyViewTransitionToHostInstances(
521
child.child,