Skip to content

Commit 9536fc1

Browse files
committed
Skip cancel/restore name on comment nodes and warn in DEV
1 parent 104322b commit 9536fc1

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,8 +1549,23 @@ export function cancelRootViewTransitionName(rootContainer: Container): void {
15491549
rootContainer.nodeType === DOCUMENT_NODE
15501550
? (rootContainer: any).documentElement
15511551
: rootContainer.ownerDocument.documentElement;
1552+
1553+
if (
1554+
!disableCommentsAsDOMContainers &&
1555+
rootContainer.nodeType === COMMENT_NODE
1556+
) {
1557+
if (__DEV__) {
1558+
console.warn(
1559+
'Cannot cancel root view transition on a comment node. All view transitions will be globally scoped.',
1560+
);
1561+
}
1562+
return;
1563+
}
1564+
15521565
if (
15531566
documentElement !== null &&
1567+
(disableCommentsAsDOMContainers ||
1568+
rootContainer.nodeType !== COMMENT_NODE) &&
15541569
// $FlowFixMe[prop-missing]
15551570
documentElement.style.viewTransitionName === ''
15561571
) {
@@ -1594,7 +1609,13 @@ export function restoreRootViewTransitionName(rootContainer: Container): void {
15941609
containerInstance = (rootContainer: any);
15951610
}
15961611
if (
1597-
containerInstance.style &&
1612+
!disableCommentsAsDOMContainers &&
1613+
containerInstance.nodeType === COMMENT_NODE
1614+
) {
1615+
return;
1616+
}
1617+
if (
1618+
// $FlowFixMe[prop-missing]
15981619
containerInstance.style.viewTransitionName === 'root'
15991620
) {
16001621
// If we moved the root view transition name to the container in a gesture
@@ -1710,6 +1731,10 @@ export function cloneRootViewTransitionContainer(
17101731
containerInstance = (rootContainer: any).body;
17111732
} else if (rootContainer.nodeName === 'HTML') {
17121733
containerInstance = (rootContainer.ownerDocument.body: any);
1734+
} else if (rootContainer.nodeType === COMMENT_NODE) {
1735+
throw new Error(
1736+
'Cannot use a startGestureTransition() with a comment node root.',
1737+
);
17131738
} else {
17141739
// If the container is not the whole document, then we ideally should probably
17151740
// clone the whole document outside of the React too.

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ export let shouldFireAfterActiveInstanceBlur: boolean = false;
306306
let viewTransitionContextChanged: boolean = false;
307307
let inUpdateViewTransition: boolean = false;
308308
let rootViewTransitionAffected: boolean = false;
309+
let rootViewTransitionNameCanceled: boolean = false;
309310

310311
function isHydratingParent(current: Fiber, finishedWork: Fiber): boolean {
311312
if (finishedWork.tag === ActivityComponent) {
@@ -2737,6 +2738,7 @@ function commitAfterMutationEffectsOnFiber(
27372738
switch (finishedWork.tag) {
27382739
case HostRoot: {
27392740
viewTransitionContextChanged = false;
2741+
rootViewTransitionNameCanceled = false;
27402742
pushViewTransitionCancelableScope();
27412743
recursivelyTraverseAfterMutationEffects(root, finishedWork, lanes);
27422744
if (!viewTransitionContextChanged && !rootViewTransitionAffected) {
@@ -2755,6 +2757,7 @@ function commitAfterMutationEffectsOnFiber(
27552757
}
27562758
// We also cancel the root itself.
27572759
cancelRootViewTransitionName(root.containerInfo);
2760+
rootViewTransitionNameCanceled = true;
27582761
}
27592762
popViewTransitionCancelableScope(null);
27602763
break;
@@ -3613,7 +3616,7 @@ function commitPassiveMountOnFiber(
36133616
}
36143617

36153618
if (isViewTransitionEligible) {
3616-
if (supportsMutation) {
3619+
if (supportsMutation && rootViewTransitionNameCanceled) {
36173620
restoreRootViewTransitionName(finishedRoot.containerInfo);
36183621
}
36193622
}

scripts/error-codes/codes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,5 +544,6 @@
544544
"556": "Expected prepareToHydrateHostActivityInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.",
545545
"557": "Expected to have a hydrated activity instance. This error is likely caused by a bug in React. Please file an issue.",
546546
"558": "Client rendering an Activity suspended it again. This is a bug in React.",
547-
"559": "Expected to find a host node. This is a bug in React."
547+
"559": "Expected to find a host node. This is a bug in React.",
548+
"560": "Cannot use a startGestureTransition() with a comment node root."
548549
}

0 commit comments

Comments
 (0)