-
-
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
[styles] Strict Mode support #18018
Comments
className
did not match.className
did not match.
@oliviertassinari I think this is a bug, not a question. If you see my reproduction steps, the only thing I did was to add StrictMode to material-ui/example/nextjs - no other code is changed |
thank you for reporting it. I'm experiencing the same issue here.. |
I was able to solve it by going back to this versions:
_document.js:
_app.js:
StylingProvider.js:
getPageContext.js :
I hope this will help someone straggling with MaterialUI and Next.js ClassName issue in the future |
@amiral-jion it's good to know that it's a bug introduced in one of the new versions :) |
I think this will take bit more time to fix since We need to fix the following tests first: Switch those to |
Could it be a recent regression linked to a dependency/transitive dependency? |
After more investigation, the problem seems to be the following: React randomly? triggers two renders before the hydration. The |
For me it was the automatic imports of my IDE after copy pasting components around. |
The All toggle doesn't render correctly due to this issue --> mui/material-ui#18018. I've set the All toggle to render only when there are more than one reporters. This fixes the visual render for now but leaves the warning about the className mismatch between server and the client in the console.
Having the same issue as well:
Is this a known bug? |
Is there an acceptable workaround for this at the moment? This brakes SSR for me which basically makes material-ui inviable because the app requires SSR. |
@fullofcaffeine The workaround is not to use dynamic styles. This doesn't impact the core components, it would impact @material-ui/styles that accepts props and the Box, when used with JSS (no emotion or styled-components). |
@oliviertassinari Thanks for the prompt reply. As far as I understand, dynamic styles are pretty core to the mui customization workflow. I haven't paid much attention, but I think I'm using them heavily. Does the workaround you describe require me not to use |
None of the core components use the dynamic styles yet because we have uncovered too many issues with them. I don't understand your question. |
I don't use material, but use next and sc, so it's problem about them. |
@oliviertassinari Sorry if I wasn't clear. Perhaps I don't understand exactly what you meant by dynamic styles. Is that the mechanism by which you customize the CSS by means of |
It's different, the issue is with https://material-ui.com/styles/basics/#adapting-based-on-props that we don't use with the core components yet because of a bunch of issues we have uncovered. |
@oliviertassinari I'm not using this feature, yet I'm still getting a broken layout after the view is hydrated. |
Hi @oliviertassinari I am also facing this issue of differnet classnames on server and at client side and I am passing props in many parts of my application. Is there any workaround available or I will have to stop passing props from the entire appication(that will be a very tedious task). Please help. |
@oliviertassinari can you please look into it on priority if possible ? I am stuck right now. Will have to update the css from the whole application because of this issue. |
@ankit-gupta1307 have tried to check in your whole application if u have imports with duplicate component directory like this example: |
Yes @adir1661 I have looked into my application, don't have these kind of import statements. |
same here, got the same bug and none of that double folder import. I'm using dynamic styles . |
Can anyone here help ? |
Something really unexpected fixed the bug for me, hope this will be the same for everyone. I replaced After that, I don't have any more problems with dynamic styling in SSR. Really hope this will fix the bug for all of you. |
Commented out StrictMode due to warnings in material-ui created from page dropdown in the table. See mui/material-ui#18018 and mui/material-ui#20012
Can you please explain that issue in detail - why is that happening? AFAIK React.StrictMode only highlights potential issues, but in this thread I see it even breaks the code. How? |
It highlights actual issues. It is intended that components inside React.StrictMode break if they're not concurrent safe. |
An update, this issue is being resolved in v5 thanks to #22342 and the new |
That's great @oliviertassinari will give it a try |
This comment has been minimized.
This comment has been minimized.
Hi guys! I am using nextjs and material ui, I read all of the previous comments and nothing worked for me, then changed to v5 of material ui and still get this error |
This comment has been minimized.
This comment has been minimized.
Hi Guys, I encountered this issue with I encountered this issue with AppBar in Material UI. after I deleted these ClassName and write inline styles, it solves the problem. |
An update, we have now made enough progress with the new
This was made possible by the awesome work of @mnajdova. |
Commented out StrictMode due to warnings in material-ui created from page dropdown in the table. See mui/material-ui#18018 and mui/material-ui#20012
Just in case this helps someone: I was able to get rid of the |
First of all, thank you all very much for the amazing material-ui.
I started my project from https://github.com/mui-org/material-ui/tree/master/examples/nextjs
Lately, I started to notice that my page after hydration looked weird - some styles were missing and some other times they were not applied to the expected elements.
Using React.StrictMode it tells me the following error:
Warning: Prop
className
did not match. Server: "MuiSvgIcon-root makeStyles-lightBulb-47" Client: "MuiSvgIcon-root makeStyles-lightBulb-48"Current Behavior 😯
Looks like the classNames generated at server rendering are different to the ones generated at browser rendering time.
Expected Behavior 🤔
Server-side rendering and client-side rendering should generate the same class names.
Steps to Reproduce 🕹
Steps (Code Sandbox):
Warning: Prop
className
did not match. Server: "MuiSvgIcon-root makeStyles-lightBulb-47" Client: "MuiSvgIcon-root makeStyles-lightBulb-48"Steps (Running locally)
Warning: Prop
className
did not match. Server: "MuiSvgIcon-root makeStyles-lightBulb-47" Client: "MuiSvgIcon-root makeStyles-lightBulb-48"Context 🔦
The reproduction of the error will look something like:
![next-material](https://user-images.githubusercontent.com/9042965/67482320-7c565400-f65b-11e9-8133-98ed01227fb2.png)
The only difference between my repository (example) and material-ui/examples/nextjs is the React.StrictMode instead of React.Fragment inside _app.js
Your Environment 🌎
PS - I saw that in the past some issues were created for something similar to this, but I couldn't apply the solutions on those issues to this specific issue. Most of those issues were using styled-components and none was using the material-ui example.
The text was updated successfully, but these errors were encountered: