-
Notifications
You must be signed in to change notification settings - Fork 27.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
Prop className
did not match error after upgrading to React 18
#36284
Comments
I replaced the steps to reproduce with a link to a repo that will make reproducing the issue easy. |
You are trying to use an old version of the MUI, try using this: |
That is what I used to start with, but I downgraded to MUI v4 to match what we are using. The issue doesn’t exist in v5 because v5 no longer uses JSS for styling. Upgrading to v5 isn’t an option for us because of the amount of work it would take to convert all styling from JSS to emotion. |
I just did that and got the same result: Prop className did not match. I'd share it, but the code is nearly identical to the repo that I linked in the description. |
I'm able to reproduce this with a similar setup but with styled-components@5.3.3. |
I think i had the same issue, i resolved this with adding this to the next js config: |
From the maintainer of MUI, It appears that v4 is not intended to be used with React 18: mui/material-ui#32685 (comment) This is not a Next.js issue then, so I'm closing. Those reporting an issue with |
balazsorban44 I have MUI v4 and React 18 working well together in another repo. Once Next.js is added to the mix, the error in this issue occurs. |
That other project might not rely on server-side rendering or static optimization, so hydration might not be a concern. Useful resources: |
balazsorban44 Correct, the other project doesn't use Next.js or any server side rendering. The project that does have the issue uses Next.js with no dynamic content. All pages are built during the build process using content from a JSON file. Therefore, I still believe this is a valid issue and should be reopened. |
Makes sense then. As commented above though, the MUI team does not consider v4 fit to be used with React 18 so there is nothing for the Next.js team to do here. You can try upgrading to the minimum recommended version and if you still see issues with Next.js, please add a new reproduction and let us know! |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
I don't have a .babelrc file.
Exports from next.config.js
Excerpt from _document.tsx
What browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
No response
Describe the Bug
After upgrading from React 17 to React 18, I now get the following warning:
After running
next dev
the app will load with all styles and no warning. However, as soon as I navigate to a different page or refresh, the warning appears and many styles are missing.I tried all of the following solutions, but they didn't work for me.
- https://binyamin.medium.com/solving-the-styled-components-warning-in-next-js-with-babel-83080e45a0ff
- https://github.com/vercel/next.js/pull/8791/files
- #11600 (comment)
- #11600 (comment)
- #7322 (comment)
- #7322 (comment)
- https://github.com/nblthree/nextjs-with-material-ui-and-styled-components/blob/master/.babelrc
- https://stackoverflow.com/a/69169144/3474412
I confirmed the issue with both next v12.1.5 and v12.1.6-canary.4
Expected Behavior
No warnings appear and all components are properly styled.
To Reproduce
yarn install
yarn start
The text was updated successfully, but these errors were encountered: