Skip to content

Commit e14d061

Browse files
committed
[Fiber] Use className on <ViewTransition> to assign view-transition-class (#31999)
Stacked on #31975. This is the primary way we recommend styling your View Transitions since it allows for reusable styling such as a CSS library specializing in View Transitions in a way that's composable and without naming conflicts. E.g. ```js <ViewTransition className="enter-slide-in exit-fade-out update-cross-fade"> ``` This doesn't change the HTML `class` attribute. It's not a CSS class. Instead it assign the `view-transition-class` style prop of the underlying DOM node while it's transitioning. You can also just use `<div style={{viewTransitionClass: ...}}>` on the DOM node but it's convenient to control the Transition completely from the outside and conceptually we're transitioning the whole fragment. You can even make Transition components that just wraps existing components. `<RevealTransition><Component /></RevealTransition>` this way. Since you can also have multiple wrappers for different circumstances it allows React's heuristics to use different classes for different scenarios. We'll likely add more options like configuring different classes for different `types` or scenarios that can't be described by CSS alone. ## CSS Modules ```js import transitions from './transitions.module.css'; <ViewTransition className={transitions.bounceIn}>...</ViewTransition> ``` CSS Modules works well with this strategy because you can have globally unique namespaces and define your transitions in the CSS modules as a library that you can import. [As seen in the fixture here.](8b91b37#diff-b4d9854171ffdac4d2c01be92a5eff4f8e9e761e6af953094f99ca243b054a85R11) I did notice an unfortunate bug in how CSS Modules (at least in Webpack) generates class names. Sometimes the `+` character is used in the hash of the class name which is not valid for `view-transition-class` and so it breaks. I had to rename my class names until the hash yielded something different to work around it. Ideally that bug gets fixed soon. ## className, rly? `className` isn't exactly the most loved property name, however, I'm using `className` here too for consistency. Even though in this case there's no direct equivalent DOM property name. The CSS property is named `viewTransitionClass`, but the "viewTransition" prefix is implied by the Component it is on in this case. For most people the fact that this is actually a different namespace than other CSS classes doesn't matter. You'll most just use a CSS library anyway and conceptually you're just assigning classes the same way as `className` on a DOM node. But if we ever rename the `class` prop then we can do that for this one as well. DiffTrain build for [3a5496b](3a5496b)
1 parent bc67e62 commit e14d061

34 files changed

+892
-892
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a4d122f2d192fe0b6480e669cca43c8f953aaf85
1+
38127b281567d43972b7fb44c3fcb0d1806e7c10
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a4d122f2d192fe0b6480e669cca43c8f953aaf85
1+
38127b281567d43972b7fb44c3fcb0d1806e7c10

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ __DEV__ &&
19441944
exports.useTransition = function () {
19451945
return resolveDispatcher().useTransition();
19461946
};
1947-
exports.version = "19.1.0-www-classic-a4d122f2-20250108";
1947+
exports.version = "19.1.0-www-classic-3a5496b3-20250108";
19481948
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19491949
"function" ===
19501950
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ __DEV__ &&
19441944
exports.useTransition = function () {
19451945
return resolveDispatcher().useTransition();
19461946
};
1947-
exports.version = "19.1.0-www-modern-a4d122f2-20250108";
1947+
exports.version = "19.1.0-www-modern-3a5496b3-20250108";
19481948
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19491949
"function" ===
19501950
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,4 +630,4 @@ exports.useSyncExternalStore = function (
630630
exports.useTransition = function () {
631631
return ReactSharedInternals.H.useTransition();
632632
};
633-
exports.version = "19.1.0-www-classic-a4d122f2-20250108";
633+
exports.version = "19.1.0-www-classic-3a5496b3-20250108";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,4 +630,4 @@ exports.useSyncExternalStore = function (
630630
exports.useTransition = function () {
631631
return ReactSharedInternals.H.useTransition();
632632
};
633-
exports.version = "19.1.0-www-modern-a4d122f2-20250108";
633+
exports.version = "19.1.0-www-modern-3a5496b3-20250108";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ exports.useSyncExternalStore = function (
634634
exports.useTransition = function () {
635635
return ReactSharedInternals.H.useTransition();
636636
};
637-
exports.version = "19.1.0-www-classic-a4d122f2-20250108";
637+
exports.version = "19.1.0-www-classic-3a5496b3-20250108";
638638
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
639639
"function" ===
640640
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ exports.useSyncExternalStore = function (
634634
exports.useTransition = function () {
635635
return ReactSharedInternals.H.useTransition();
636636
};
637-
exports.version = "19.1.0-www-modern-a4d122f2-20250108";
637+
exports.version = "19.1.0-www-modern-3a5496b3-20250108";
638638
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
639639
"function" ===
640640
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16933,10 +16933,10 @@ __DEV__ &&
1693316933
(function () {
1693416934
var internals = {
1693516935
bundleType: 1,
16936-
version: "19.1.0-www-classic-a4d122f2-20250108",
16936+
version: "19.1.0-www-classic-3a5496b3-20250108",
1693716937
rendererPackageName: "react-art",
1693816938
currentDispatcherRef: ReactSharedInternals,
16939-
reconcilerVersion: "19.1.0-www-classic-a4d122f2-20250108"
16939+
reconcilerVersion: "19.1.0-www-classic-3a5496b3-20250108"
1694016940
};
1694116941
internals.overrideHookState = overrideHookState;
1694216942
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -16970,7 +16970,7 @@ __DEV__ &&
1697016970
exports.Shape = Shape;
1697116971
exports.Surface = Surface;
1697216972
exports.Text = Text;
16973-
exports.version = "19.1.0-www-classic-a4d122f2-20250108";
16973+
exports.version = "19.1.0-www-classic-3a5496b3-20250108";
1697416974
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1697516975
"function" ===
1697616976
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.modern.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16705,10 +16705,10 @@ __DEV__ &&
1670516705
(function () {
1670616706
var internals = {
1670716707
bundleType: 1,
16708-
version: "19.1.0-www-modern-a4d122f2-20250108",
16708+
version: "19.1.0-www-modern-3a5496b3-20250108",
1670916709
rendererPackageName: "react-art",
1671016710
currentDispatcherRef: ReactSharedInternals,
16711-
reconcilerVersion: "19.1.0-www-modern-a4d122f2-20250108"
16711+
reconcilerVersion: "19.1.0-www-modern-3a5496b3-20250108"
1671216712
};
1671316713
internals.overrideHookState = overrideHookState;
1671416714
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -16742,7 +16742,7 @@ __DEV__ &&
1674216742
exports.Shape = Shape;
1674316743
exports.Surface = Surface;
1674416744
exports.Text = Text;
16745-
exports.version = "19.1.0-www-modern-a4d122f2-20250108";
16745+
exports.version = "19.1.0-www-modern-3a5496b3-20250108";
1674616746
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1674716747
"function" ===
1674816748
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)