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
[zero] Set up Material UI migration demos #41267
Conversation
Netlify deploy previewhttps://deploy-preview-41267--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
@@ -97,6 +116,7 @@ const zeroPluginOptions = { | |||
transformLibraries: ['local-ui-lib'], | |||
sourceMap: true, | |||
displayName: true, | |||
transformSx: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sx
support is not fully working. Need to disable it to be able to render demos.
@@ -0,0 +1,86 @@ | |||
'use client'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this page is generated from the script https://github.com/mui/material-ui/pull/41267/files#diff-a4d30ddb2faa2486c2c65415ce350349fb32db41f7467e0d5680ac41b41febd5
@@ -0,0 +1,13 @@ | |||
// theme for MUI System (emotion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of demos are using Stack
component by targeting margin
of its children. The converted component styles are extracted so margin can not be overridden by Stack. We can't change the demos, so need to use ThemeProvider to change to gap instead.
"react-router": "^6.22.1", | ||
"react-router-dom": "^6.22.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required by vite-plugin-pages
@@ -29,6 +32,7 @@ | |||
"@vitejs/plugin-react": "^4.2.1", | |||
"postcss": "^8.4.35", | |||
"postcss-combine-media-query": "^1.0.1", | |||
"vite": "5.0.12" | |||
"vite": "5.0.12", | |||
"vite-plugin-pages": "^0.32.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To enable file system routing in vite.
@@ -1,7 +1,8 @@ | |||
{ | |||
"extends": "../../tsconfig.json", | |||
"compilerOptions": { | |||
"jsx": "react-jsx" | |||
"jsx": "react-jsx", | |||
"allowImportingTsExtensions": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to explicitly do import Demos from '../path/to/Demo.tsx
to use tsx file because .js
is not out of the box supported in Vite.
package.json
Outdated
@@ -112,6 +112,7 @@ | |||
"@mui/joy": "workspace:*", | |||
"@mui/material": "workspace:^", | |||
"@mui/utils": "workspace:^", | |||
"@mui/zero-runtime": "workspace:^", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add @mui/zero-runtime
at the root project, so that@mui/material
works inside nextjs app.
@@ -114,5 +115,5 @@ export function zeroVitePlugin(options: ZeroVitePluginOptions) { | |||
...rest, | |||
}); | |||
|
|||
return [injectMUITokensPlugin(), intermediateBabelPlugin(), zeroPlugin]; | |||
return [injectMUITokensPlugin(), transformSx ? intermediateBabelPlugin() : null, zeroPlugin]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vite plugin was missing transformSx
config.
Please add the instructions on how to run the script in the PR description too, so we can test it with a few components. |
Did you check the sx prop? It doesn't seem to work on the Letters and Sizes avatar examples. |
Yes, |
const filenames = await fse.readdir( | ||
path.join(process.cwd(), `docs/data/material/components/${dataFolderName}`), | ||
); | ||
const tsFiles = filenames.filter((filename) => filename.endsWith('.tsx')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit-pick, for some demos we have only js version, but we can simplify and depend on the TSX demos for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: .js demo won't work with Vite with the current configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, I pushed some small improvements on the script. I tried it with the badge component, it works as expected.
I think it'd be best if there is a way to test with the built files in |
Got your point, the current setup uses workspace which is not the build folder, is that what you meant? |
Correct. If not in dev, at least in the build step it should consider the |
This reverts commit 309e443.
@brijeshb42 I think I got it working in b81f297 This is the files pass through wyw-in-js which looks the same I got in intermediate-repo (it contains emotion).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope the changes in the packages to use file paths is just temporary. Rest all looks good.
This reverts commit b81f297.
Okay, I'll go with this until we have a better solution for both dev and production environment. |
Goal
This PR sets up the structure of internal nextjs and vite apps to test the Material UI components while converting them to support Zero Runtime.
Changes
Test
pnpm install
pnpm build
- build mui-material and zero-* packagespnpm --filter @app/vite-app run dev
andpnpm --filter @app/next-app run dev
in separate terminalsRun the script
The
component
comes from the valid path ofhttps://mui/material-ui/react-<component>
, e.g.react-avatar
,react-chip
, etc.