Skip to content

Commit 4280563

Browse files
authored
Mark shouldStartViewTransition as true when there's an enter animation (#32764)
Typically we mark the name of things that might animate in the snapshot phase. At the same time we track that should call startViewTransition too. However, we don't do this for "enter" since they're only marked later. Leading to having just an "enter" not to animate unless there's at least another update too. This tracks if there's a ViewTransitionComponent in the tree that enters. Luckily we know that from the static flag so we don't have to traverse it.
1 parent 3e88e97 commit 4280563

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: packages/react-reconciler/src/ReactFiberCommitViewTransitions.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ export function trackAppearingViewTransition(
6767
appearingViewTransitions.set(name, state);
6868
}
6969

70+
export function trackEnterViewTransitions(placement: Fiber): void {
71+
if (
72+
placement.tag === ViewTransitionComponent ||
73+
(placement.subtreeFlags & ViewTransitionStatic) !== NoFlags
74+
) {
75+
// If an inserted or appearing Fiber is a ViewTransition component or has one as
76+
// an immediate child, then that will trigger as an "Enter" in future passes.
77+
// We don't do anything else for that case in the "before mutation" phase but we
78+
// still have to mark it as needing to call startViewTransition if nothing else
79+
// updates.
80+
shouldStartViewTransition = true;
81+
}
82+
}
83+
7084
// We can't cancel view transition children until we know that their parent also
7185
// don't need to transition.
7286
export let viewTransitionCancelableChildren: null | Array<
@@ -119,7 +133,6 @@ function applyViewTransitionToHostInstancesRecursive(
119133
let inViewport = false;
120134
while (child !== null) {
121135
if (child.tag === HostComponent) {
122-
shouldStartViewTransition = true;
123136
const instance: Instance = child.stateNode;
124137
if (collectMeasurements !== null) {
125138
const measurement = measureInstance(instance);
@@ -132,6 +145,7 @@ function applyViewTransitionToHostInstancesRecursive(
132145
inViewport = true;
133146
}
134147
}
148+
shouldStartViewTransition = true;
135149
applyViewTransitionName(
136150
instance,
137151
viewTransitionHostInstanceIdx === 0

Diff for: packages/react-reconciler/src/ReactFiberCommitWork.js

+7
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ import {
235235
commitFragmentInstanceInsertionEffects,
236236
} from './ReactFiberCommitHostEffects';
237237
import {
238+
trackEnterViewTransitions,
238239
commitEnterViewTransitions,
239240
commitExitViewTransitions,
240241
commitBeforeUpdateViewTransition,
@@ -338,6 +339,9 @@ function commitBeforeMutationEffects_begin(isViewTransitionEligible: boolean) {
338339
// to trigger updates of any nested view transitions and we shouldn't
339340
// have any other before mutation effects since snapshot effects are
340341
// only applied to updates. TODO: Model this using only flags.
342+
if (isViewTransitionEligible) {
343+
trackEnterViewTransitions(fiber);
344+
}
341345
commitBeforeMutationEffects_complete(isViewTransitionEligible);
342346
continue;
343347
}
@@ -367,6 +371,9 @@ function commitBeforeMutationEffects_begin(isViewTransitionEligible: boolean) {
367371
// to trigger updates of any nested view transitions and we shouldn't
368372
// have any other before mutation effects since snapshot effects are
369373
// only applied to updates. TODO: Model this using only flags.
374+
if (isViewTransitionEligible) {
375+
trackEnterViewTransitions(fiber);
376+
}
370377
commitBeforeMutationEffects_complete(isViewTransitionEligible);
371378
continue;
372379
}

0 commit comments

Comments
 (0)