-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
makeStyles
with a function css rule entry doesn't work on react 18 using react-dom/client createRoot
#32881
Comments
Hi @rart, Latest MUI version includes a codemod for automatic migration from JSS to TSS. https://mui.com/material-ui/guides/migration-v4/#2-use-tss-react Best regards |
Thanks for the update, @garronej Back when we did the migration to mui v5 (very early on), I did just try the codemod and it doesn't work over a previously updated codebase. Because we had already upgraded to MUI v5, our makeStyles import statements are from Is there a post v5 upgrade codemod that would work on already updated codebases? Or that helps with the other issues too? Also, being @mui/styles deprecated I assume it means this ticket won't get fixed? |
I didn't write the codemod but there is at least one test case that does remove
If it's only that you could try a search/replace and run the codemod again. Anyway, the migration is quite easy to perform by hand on a typescript codebase, assuming it isn't huge.
I woudn't count to much on it. Ref. Good luck! |
Correction: the codemod does remove the We did the migration to tss and it was a lot of manual tweaking even with the codemod but the problem is gone so looks like the issue is indeed related to the incompatibility of I'll leave the ticket open for you guys to decide if you want to address or close. |
thanks for the feedback! |
@rart FYI - @joshkel did enhance the codemod to support replacing I wrote the initial version of the jss-to-tss-react codemod. If there are some patterns that were common in your code that it didn't cover, please share some code examples. I'll be able to tell fairly quickly whether or not it's a pattern that I could easily enhance the codemod to cover. |
We already migrated, but that's a great addition 👏
Because the migration was done some weeks ago, I've now forgotten some of the struggles or some details. But here's what I remember:
import createStyles from '@mui/styles/createStyles';
import makeStyles from '@mui/styles/makeStyles';
const useStyles = makeStyles((theme) =>
createStyles<ViewToolbarClassKey, ViewToolbarStyles>({
appBar: (styles) => ({
borderBottom: `1px solid ${theme.palette.divider}`
...styles.appBar
}), Notice how the rule is a function that receives an arg that's not destructured. The codemod only worked if the argument was destructured. We had to covert the above to the below before running the codemod: const useStyles = makeStyles((theme) =>
createStyles<ViewToolbarClassKey, ViewToolbarStyles>({
appBar: ({ appBar }) => ({
borderBottom: `1px solid ${theme.palette.divider}`
...appBar
}), Other things I remember vaguely is that there were some additional strange things post codemod. For example,
|
The |
Duplicates
Latest version
Current behavior 😯
On react 18, when rendering using
ReactDomClient.createRoot().render(...)
, using function css rule definitions doesn't work correctly — styles are missing from the runtime, despite the classes being applied to the elements.Still on react 18, rendering via
ReactDom.render
does work.This is particularly problematic because this is the new default of create react app.
Expected behavior 🤔
Function style rules work and apply just like plain objects independently of the react render method used.
Steps to reproduce 🕹
Steps:
yarn create react-app make-styles-test
)Live example @ https://codesandbox.io/s/mui-makestyles-functions-issue-jhjfq5
The example renders two Typography components; each with a class produced by a
makeStyles({})()
. One of the Typography elements takes a class for a style rule body returned by a function and the other from a plain object. The style rules are identical, the only difference is the plain object vs function definitions. When rendered via createRoot.render, you can see one of the Typography elements doesn't have the styling that the class defines (black background, red font color).Notice at the bottom of the
index.tsx
file the two ways of rendering (ReactDom.render
vsReactDomClient.createRoot.render
). One works and the other one doesn't. You may comment/uncomment the two ways to see the different results.Context 🔦
We have an npm package with components based on mui. Despite our package being on
mui@^5
, a number of our components haven't fully migrated out of the @mui/styles into the new style system. CRA latest usescreateRoot().render()
by default and, when creating a CRA app and using our package, a lot of our styles are simply missing.The issue is not specific to our package (see clean codesandbox example).
Your environment 🌎
Chrome & Safari. Probably all.
The text was updated successfully, but these errors were encountered: