Skip to content

[Fiber] Use className on <ViewTransition> to assign view-transition-class #31999

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 3 commits into from
Jan 8, 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
24 changes: 22 additions & 2 deletions fixtures/view-transition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
"private": true,
"devDependencies": {
"concurrently": "3.1.0",
"http-proxy-middleware": "0.17.3",
"react-scripts": "0.9.5"
"http-proxy-middleware": "3.0.3",
"react-scripts": "5.0.1",
"@babel/plugin-proposal-private-property-in-object": "7.21.11"
},
"dependencies": {
"@babel/register": "^7.25.9",
"express": "^4.14.0",
"ignore-styles": "^5.0.1",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"scripts": {
"predev": "cp -r ../../build/oss-experimental/* ./node_modules/",
"prestart": "cp -r ../../build/oss-experimental/* ./node_modules/",
Expand All @@ -24,5 +32,17 @@
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
9 changes: 5 additions & 4 deletions fixtures/view-transition/server/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require('ignore-styles');
const babelRegister = require('babel-register');
const babelRegister = require('@babel/register');
const proxy = require('http-proxy-middleware');

babelRegister({
ignore: /\/(build|node_modules)\//,
ignore: [/\/(build|node_modules)\//],
presets: ['react-app'],
});

Expand Down Expand Up @@ -37,9 +37,10 @@ app.use(express.static(path.resolve(__dirname, '..', 'build')));
if (process.env.NODE_ENV === 'development') {
app.use(
'/',
proxy({
proxy.createProxyMiddleware({
ws: true,
target: 'http://localhost:3001',
changeOrigin: true,
target: 'http://127.0.0.1:3001',
})
);
}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/view-transition/server/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (process.env.NODE_ENV === 'development') {
// 'main.css': '',
};
} else {
assets = require('../build/asset-manifest.json');
assets = require('../build/asset-manifest.json').files;
}

export default function render(url, res) {
Expand Down
14 changes: 14 additions & 0 deletions fixtures/view-transition/src/components/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import React, {

import './Page.css';

import transitions from './Transitions.module.css';

const a = (
<div key="a">
<ViewTransition>
Expand All @@ -24,6 +26,17 @@ const b = (
</div>
);

function Component() {
return (
<ViewTransition
className={
transitions['enter-slide-right'] + ' ' + transitions['exit-slide-left']
}>
<p>Slide In from Left, Slide Out to Right</p>
</ViewTransition>
);
}

export default function Page() {
const [show, setShow] = useState(false);
useEffect(() => {
Expand Down Expand Up @@ -72,6 +85,7 @@ export default function Page() {
<div>!!</div>
</ViewTransition>
</Activity>
{show ? <Component /> : <p>&nbsp;</p>}
</div>
</ViewTransition>
</div>
Expand Down
28 changes: 28 additions & 0 deletions fixtures/view-transition/src/components/Transitions.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@keyframes enter-slide-right {
0% {
opacity: 0;
translate: -200px 0;
}
100% {
opacity: 1;
translate: 0 0;
}
}

@keyframes exit-slide-left {
0% {
opacity: 1;
translate: 0 0;
}
100% {
opacity: 0;
translate: 200px 0;
}
}

::view-transition-new(.enter-slide-right):only-child {
animation: enter-slide-right ease-in 0.25s;
}
::view-transition-old(.exit-slide-left):only-child {
animation: exit-slide-left ease-in 0.25s;
}
Loading
Loading