Skip to content
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

Rename <ViewTransition className="..."> to <ViewTransition default="..."> #32734

Merged
merged 4 commits into from
Mar 26, 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
8 changes: 4 additions & 4 deletions fixtures/view-transition/src/components/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const b = (
function Component() {
return (
<ViewTransition
className={
default={
transitions['enter-slide-right'] + ' ' + transitions['exit-slide-left']
}>
<p className="roboto-font">Slide In from Left, Slide Out to Right</p>
Expand Down Expand Up @@ -97,17 +97,17 @@ export default function Page({url, navigate}) {
}}>
{url === '/?b' ? 'Goto A' : 'Goto B'}
</button>
<ViewTransition className="none">
<ViewTransition default="none">
<div>
<ViewTransition>
<div>
<ViewTransition className={transitions['slide-on-nav']}>
<ViewTransition default={transitions['slide-on-nav']}>
<h1>{!show ? 'A' : 'B' + counter}</h1>
</ViewTransition>
</div>
</ViewTransition>
<ViewTransition
className={{
default={{
'navigation-back': transitions['slide-right'],
'navigation-forward': transitions['slide-left'],
}}>
Expand Down
12 changes: 6 additions & 6 deletions packages/react-reconciler/src/ReactFiberApplyGesture.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function trackDeletedPairViewTransitions(deletion: Fiber): void {
// and can stop searching (size reaches zero).
pairs.delete(name);
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
props.share,
);
if (className !== 'none') {
Expand Down Expand Up @@ -196,7 +196,7 @@ function trackEnterViewTransitions(deletion: Fiber): void {
? appearingViewTransitions.get(name)
: undefined;
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
pair !== undefined ? props.share : props.enter,
);
if (className !== 'none') {
Expand Down Expand Up @@ -259,7 +259,7 @@ function applyAppearingPairViewTransition(child: Fiber): void {
// Note that this class name that doesn't actually really matter because the
// "new" side will be the one that wins in practice.
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
props.share,
);
if (className !== 'none') {
Expand All @@ -282,7 +282,7 @@ function applyExitViewTransition(placement: Fiber): void {
const props: ViewTransitionProps = placement.memoizedProps;
const name = getViewTransitionName(props, state);
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
// Note that just because we don't have a pair yet doesn't mean we won't find one
// later. However, that doesn't matter because if we do the class name that wins
// is the one applied by the "new" side anyway.
Expand All @@ -307,7 +307,7 @@ function applyNestedViewTransition(child: Fiber): void {
const props: ViewTransitionProps = child.memoizedProps;
const name = getViewTransitionName(props, state);
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
props.update,
);
if (className !== 'none') {
Expand Down Expand Up @@ -336,7 +336,7 @@ function applyUpdateViewTransition(current: Fiber, finishedWork: Fiber): void {
// want the props from "current" since that's the class that would've won if
// it was the normal direction. To preserve the same effect in either direction.
const className: ?string = getViewTransitionClassName(
newProps.className,
newProps.default,
newProps.update,
);
if (className === 'none') {
Expand Down
21 changes: 21 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export let didWarnAboutReassigningProps: boolean;
let didWarnAboutRevealOrder;
let didWarnAboutTailOptions;
let didWarnAboutDefaultPropsOnFunctionComponent;
let didWarnAboutClassNameOnViewTransition;

if (__DEV__) {
didWarnAboutBadClass = ({}: {[string]: boolean});
Expand All @@ -332,6 +333,7 @@ if (__DEV__) {
didWarnAboutRevealOrder = ({}: {[empty]: boolean});
didWarnAboutTailOptions = ({}: {[string]: boolean});
didWarnAboutDefaultPropsOnFunctionComponent = ({}: {[string]: boolean});
didWarnAboutClassNameOnViewTransition = ({}: {[string]: boolean});
}

export function reconcileChildren(
Expand Down Expand Up @@ -3295,6 +3297,25 @@ function updateViewTransition(
pushMaterializedTreeId(workInProgress);
}
}
if (__DEV__) {
// $FlowFixMe[prop-missing]
if (pendingProps.className !== undefined) {
const example =
typeof pendingProps.className === 'string'
? JSON.stringify(pendingProps.className)
: '{...}';
if (!didWarnAboutClassNameOnViewTransition[example]) {
didWarnAboutClassNameOnViewTransition[example] = true;
console.error(
'<ViewTransition> doesn\'t accept a "className" prop. It has been renamed to "default".\n' +
'- <ViewTransition className=%s>\n' +
'+ <ViewTransition default=%s>',
example,
example,
);
}
}
}
if (current !== null && current.memoizedProps.name !== pendingProps.name) {
// If the name changes, we schedule a ref effect to create a new ref instance.
workInProgress.flags |= Ref | RefStatic;
Expand Down
16 changes: 8 additions & 8 deletions packages/react-reconciler/src/ReactFiberCommitViewTransitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function commitAppearingPairViewTransitions(placement: Fiber): void {
}
const name = props.name;
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
props.share,
);
if (className !== 'none') {
Expand Down Expand Up @@ -267,7 +267,7 @@ export function commitEnterViewTransitions(
const props: ViewTransitionProps = placement.memoizedProps;
const name = getViewTransitionName(props, state);
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
state.paired ? props.share : props.enter,
);
if (className !== 'none') {
Expand Down Expand Up @@ -337,7 +337,7 @@ function commitDeletedPairViewTransitions(deletion: Fiber): void {
const pair = pairs.get(name);
if (pair !== undefined) {
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
props.share,
);
if (className !== 'none') {
Expand Down Expand Up @@ -389,7 +389,7 @@ export function commitExitViewTransitions(deletion: Fiber): void {
? appearingViewTransitions.get(name)
: undefined;
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
pair !== undefined ? props.share : props.exit,
);
if (className !== 'none') {
Expand Down Expand Up @@ -470,7 +470,7 @@ export function commitBeforeUpdateViewTransition(
// a layout only change, then the "foo" class will be applied even though
// it was not actually an update. Which is a bug.
const className: ?string = getViewTransitionClassName(
newProps.className,
newProps.default,
newProps.update,
);
if (className === 'none') {
Expand All @@ -495,7 +495,7 @@ export function commitNestedViewTransitions(changedParent: Fiber): void {
const props: ViewTransitionProps = child.memoizedProps;
const name = getViewTransitionName(props, child.stateNode);
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
props.update,
);
if (className !== 'none') {
Expand Down Expand Up @@ -735,7 +735,7 @@ export function measureUpdateViewTransition(
const oldName = getViewTransitionName(oldFiber.memoizedProps, state);
// Whether it ends up having been updated or relayout we apply the update class name.
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
props.update,
);
if (className === 'none') {
Expand Down Expand Up @@ -787,7 +787,7 @@ export function measureNestedViewTransitions(
const state: ViewTransitionState = child.stateNode;
const name = getViewTransitionName(props, state);
const className: ?string = getViewTransitionClassName(
props.className,
props.default,
props.update,
);
let previousMeasurements: null | Array<InstanceMeasurement>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type ViewTransitionClass = 'none' | string | ViewTransitionClassPerType;
export type ViewTransitionProps = {
name?: string,
children?: ReactNodeList,
className?: ViewTransitionClass,
default?: ViewTransitionClass,
enter?: ViewTransitionClass,
exit?: ViewTransitionClass,
share?: ViewTransitionClass,
Expand Down Expand Up @@ -129,11 +129,5 @@ export function getViewTransitionClassName(
if (eventClassName == null) {
return className;
}
if (eventClassName === 'none') {
return eventClassName;
}
if (className != null && className !== 'none') {
return className + ' ' + eventClassName;
}
return eventClassName;
}
Loading