Skip to content

[pull] main from facebook:main #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,19 @@ export function cancelRootViewTransitionName(rootContainer: Container): void {
rootContainer.nodeType === DOCUMENT_NODE
? (rootContainer: any).documentElement
: rootContainer.ownerDocument.documentElement;

if (
!disableCommentsAsDOMContainers &&
rootContainer.nodeType === COMMENT_NODE
) {
if (__DEV__) {
console.warn(
'Cannot cancel root view transition on a comment node. All view transitions will be globally scoped.',
);
}
return;
}

if (
documentElement !== null &&
// $FlowFixMe[prop-missing]
Expand Down Expand Up @@ -1593,8 +1606,16 @@ export function restoreRootViewTransitionName(rootContainer: Container): void {
// clone the whole document outside of the React too.
containerInstance = (rootContainer: any);
}
// $FlowFixMe[prop-missing]
if (containerInstance.style.viewTransitionName === 'root') {
if (
!disableCommentsAsDOMContainers &&
containerInstance.nodeType === COMMENT_NODE
) {
return;
}
if (
// $FlowFixMe[prop-missing]
containerInstance.style.viewTransitionName === 'root'
) {
// If we moved the root view transition name to the container in a gesture
// we need to restore it now.
containerInstance.style.viewTransitionName = '';
Expand Down Expand Up @@ -1708,6 +1729,13 @@ export function cloneRootViewTransitionContainer(
containerInstance = (rootContainer: any).body;
} else if (rootContainer.nodeName === 'HTML') {
containerInstance = (rootContainer.ownerDocument.body: any);
} else if (
!disableCommentsAsDOMContainers &&
rootContainer.nodeType === COMMENT_NODE
) {
throw new Error(
'Cannot use a startGestureTransition() with a comment node root.',
);
} else {
// If the container is not the whole document, then we ideally should probably
// clone the whole document outside of the React too.
Expand Down
5 changes: 4 additions & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export let shouldFireAfterActiveInstanceBlur: boolean = false;
let viewTransitionContextChanged: boolean = false;
let inUpdateViewTransition: boolean = false;
let rootViewTransitionAffected: boolean = false;
let rootViewTransitionNameCanceled: boolean = false;

function isHydratingParent(current: Fiber, finishedWork: Fiber): boolean {
if (finishedWork.tag === ActivityComponent) {
Expand Down Expand Up @@ -2737,6 +2738,7 @@ function commitAfterMutationEffectsOnFiber(
switch (finishedWork.tag) {
case HostRoot: {
viewTransitionContextChanged = false;
rootViewTransitionNameCanceled = false;
pushViewTransitionCancelableScope();
recursivelyTraverseAfterMutationEffects(root, finishedWork, lanes);
if (!viewTransitionContextChanged && !rootViewTransitionAffected) {
Expand All @@ -2755,6 +2757,7 @@ function commitAfterMutationEffectsOnFiber(
}
// We also cancel the root itself.
cancelRootViewTransitionName(root.containerInfo);
rootViewTransitionNameCanceled = true;
}
popViewTransitionCancelableScope(null);
break;
Expand Down Expand Up @@ -3613,7 +3616,7 @@ function commitPassiveMountOnFiber(
}

if (isViewTransitionEligible) {
if (supportsMutation) {
if (supportsMutation && rootViewTransitionNameCanceled) {
restoreRootViewTransitionName(finishedRoot.containerInfo);
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/error-codes/codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,5 +544,6 @@
"556": "Expected prepareToHydrateHostActivityInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.",
"557": "Expected to have a hydrated activity instance. This error is likely caused by a bug in React. Please file an issue.",
"558": "Client rendering an Activity suspended it again. This is a bug in React.",
"559": "Expected to find a host node. This is a bug in React."
"559": "Expected to find a host node. This is a bug in React.",
"560": "Cannot use a startGestureTransition() with a comment node root."
}
Loading