Skip to content

Commit 8ade442

Browse files
committed
Don't pass "current" to measureViewTransitionHostInstances
Same thing for cancelViewTransitionHostInstances This doesn't make sense for "nested" which has not updated and so might not have an alternate. Instead we pass in the old and new name if they might be different.
1 parent e5cbce6 commit 8ade442

File tree

1 file changed

+41
-48
lines changed

1 file changed

+41
-48
lines changed

packages/react-reconciler/src/ReactFiberCommitViewTransitions.js

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -582,21 +582,21 @@ export function restoreNestedViewTransitions(changedParent: Fiber): void {
582582
}
583583

584584
export function cancelViewTransitionHostInstances(
585-
currentViewTransition: Fiber,
586585
child: null | Fiber,
586+
oldName: string,
587587
stopAtNestedViewTransitions: boolean,
588588
): void {
589589
viewTransitionHostInstanceIdx = 0;
590590
cancelViewTransitionHostInstancesRecursive(
591-
currentViewTransition,
592591
child,
592+
oldName,
593593
stopAtNestedViewTransitions,
594594
);
595595
}
596596

597597
function cancelViewTransitionHostInstancesRecursive(
598-
currentViewTransition: Fiber,
599598
child: null | Fiber,
599+
oldName: string,
600600
stopAtNestedViewTransitions: boolean,
601601
): void {
602602
if (!supportsMutation) {
@@ -605,10 +605,6 @@ function cancelViewTransitionHostInstancesRecursive(
605605
while (child !== null) {
606606
if (child.tag === HostComponent) {
607607
const instance: Instance = child.stateNode;
608-
const oldName = getViewTransitionName(
609-
currentViewTransition.memoizedProps,
610-
currentViewTransition.stateNode,
611-
);
612608
if (viewTransitionCancelableChildren === null) {
613609
viewTransitionCancelableChildren = [];
614610
}
@@ -631,8 +627,8 @@ function cancelViewTransitionHostInstancesRecursive(
631627
// inner most one is the one that handles the update.
632628
} else {
633629
cancelViewTransitionHostInstancesRecursive(
634-
currentViewTransition,
635630
child.child,
631+
oldName,
636632
stopAtNestedViewTransitions,
637633
);
638634
}
@@ -641,31 +637,31 @@ function cancelViewTransitionHostInstancesRecursive(
641637
}
642638

643639
export function measureViewTransitionHostInstances(
644-
currentViewTransition: Fiber,
645640
parentViewTransition: Fiber,
646641
child: null | Fiber,
647-
name: string,
642+
newName: string,
643+
oldName: string,
648644
className: ?string,
649645
previousMeasurements: null | Array<InstanceMeasurement>,
650646
stopAtNestedViewTransitions: boolean,
651647
): boolean {
652648
viewTransitionHostInstanceIdx = 0;
653649
return measureViewTransitionHostInstancesRecursive(
654-
currentViewTransition,
655650
parentViewTransition,
656651
child,
657-
name,
652+
newName,
653+
oldName,
658654
className,
659655
previousMeasurements,
660656
stopAtNestedViewTransitions,
661657
);
662658
}
663659

664660
function measureViewTransitionHostInstancesRecursive(
665-
currentViewTransition: Fiber,
666661
parentViewTransition: Fiber,
667662
child: null | Fiber,
668-
name: string,
663+
newName: string,
664+
oldName: string,
669665
className: ?string,
670666
previousMeasurements: null | Array<InstanceMeasurement>,
671667
stopAtNestedViewTransitions: boolean,
@@ -716,10 +712,10 @@ function measureViewTransitionHostInstancesRecursive(
716712
applyViewTransitionName(
717713
instance,
718714
viewTransitionHostInstanceIdx === 0
719-
? name
715+
? newName
720716
: // If we have multiple Host Instances below, we add a suffix to the name to give
721717
// each one a unique name.
722-
name + '_' + viewTransitionHostInstanceIdx,
718+
newName + '_' + viewTransitionHostInstanceIdx,
723719
className,
724720
);
725721
}
@@ -729,10 +725,6 @@ function measureViewTransitionHostInstancesRecursive(
729725
// animating it. However, in the current model this only works if the parent also
730726
// doesn't animate. So we have to queue these and wait until we complete the parent
731727
// to cancel them.
732-
const oldName = getViewTransitionName(
733-
currentViewTransition.memoizedProps,
734-
currentViewTransition.stateNode,
735-
);
736728
if (viewTransitionCancelableChildren === null) {
737729
viewTransitionCancelableChildren = [];
738730
}
@@ -759,10 +751,10 @@ function measureViewTransitionHostInstancesRecursive(
759751
} else {
760752
if (
761753
measureViewTransitionHostInstancesRecursive(
762-
currentViewTransition,
763754
parentViewTransition,
764755
child.child,
765-
name,
756+
newName,
757+
oldName,
766758
className,
767759
previousMeasurements,
768760
stopAtNestedViewTransitions,
@@ -781,6 +773,11 @@ export function measureUpdateViewTransition(
781773
finishedWork: Fiber,
782774
): boolean {
783775
const props: ViewTransitionProps = finishedWork.memoizedProps;
776+
const newName = getViewTransitionName(props, finishedWork.stateNode);
777+
const oldName = getViewTransitionName(
778+
current.memoizedProps,
779+
current.stateNode,
780+
);
784781
const updateClassName: ?string = getViewTransitionClassName(
785782
props.className,
786783
props.update,
@@ -807,22 +804,21 @@ export function measureUpdateViewTransition(
807804
if (layoutClassName === 'none') {
808805
// If we did not update, then all changes are considered a layout. We'll
809806
// attempt to cancel.
810-
cancelViewTransitionHostInstances(current, finishedWork.child, true);
807+
cancelViewTransitionHostInstances(finishedWork.child, oldName, true);
811808
return false;
812809
}
813810
// We didn't update but we might still apply layout so we measure each
814811
// instance to see if it moved or resized.
815812
className = layoutClassName;
816813
}
817-
const name = getViewTransitionName(props, finishedWork.stateNode);
818814
// If nothing changed due to a mutation, or children changing size
819815
// and the measurements end up unchanged, we should restore it to not animate.
820816
const previousMeasurements = current.memoizedState;
821817
const inViewport = measureViewTransitionHostInstances(
822-
current,
823818
finishedWork,
824819
finishedWork.child,
825-
name,
820+
newName,
821+
oldName,
826822
className,
827823
previousMeasurements,
828824
true,
@@ -842,28 +838,25 @@ export function measureNestedViewTransitions(changedParent: Fiber): void {
842838
let child = changedParent.child;
843839
while (child !== null) {
844840
if (child.tag === ViewTransitionComponent) {
845-
const current = child.alternate;
846-
if (current !== null) {
847-
const props: ViewTransitionProps = child.memoizedProps;
848-
const name = getViewTransitionName(props, child.stateNode);
849-
const className: ?string = getViewTransitionClassName(
850-
props.className,
851-
props.layout,
852-
);
853-
const inViewport = measureViewTransitionHostInstances(
854-
current,
855-
child,
856-
child.child,
857-
name,
858-
className,
859-
child.memoizedState,
860-
false,
861-
);
862-
if ((child.flags & Update) === NoFlags || !inViewport) {
863-
// Nothing changed.
864-
} else {
865-
scheduleViewTransitionEvent(child, props.onLayout);
866-
}
841+
const props: ViewTransitionProps = child.memoizedProps;
842+
const name = getViewTransitionName(props, child.stateNode);
843+
const className: ?string = getViewTransitionClassName(
844+
props.className,
845+
props.layout,
846+
);
847+
const inViewport = measureViewTransitionHostInstances(
848+
child,
849+
child.child,
850+
name,
851+
name, // Since this is unchanged, new and old name is the same.
852+
className,
853+
child.memoizedState,
854+
false,
855+
);
856+
if ((child.flags & Update) === NoFlags || !inViewport) {
857+
// Nothing changed.
858+
} else {
859+
scheduleViewTransitionEvent(child, props.onLayout);
867860
}
868861
} else if ((child.subtreeFlags & ViewTransitionStatic) !== NoFlags) {
869862
measureNestedViewTransitions(child);

0 commit comments

Comments
 (0)