-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Class name hydration mismatch in server and client, (Warning: Prop className
did not match Server and Client)
#12203
Comments
I have the same problem |
@amerllica Reviewing the information provided, the root of your issue isn't with right-to-left but with server-side rendering on its own. I would encourage you to simplify the problem as much as possible: for instance, removing the right-to-left handling in the app to better understand what's going on. @basicfu For people who just want to get it working without addressing the root issue, we have a flag for that: https://material-ui.com/customization/css-in-js/#global-css |
Dear @oliviertassinari , thanks for answer, Maybe you don't believe me, But I did everything I guessed, I know someone professional like you, maybe think I just leave a question to get my solution but I try everything. Without any exaggeration, EVERYTHING. When I omit Because of this I guess my issue is right to left configuration. I remove
Hence I do not wrap anything with I've no idea how to fix this. 😢 |
@amerllica Could you create a reproduction repository so I can have a look at it? Also, have you tried the |
Dear @oliviertassinari , I saw several times this word, And about |
@amerllica A "reproduction repository". "repository" is used in the git context. "reproduction" is used in this bug context. I have missed the link to https://gitlab.com/amerllica/varizHell. I will have a look at that, thank you. |
Ok, I have found the root cause of your issue. It's definitely a configuration issue. I'm updating the documentation "Troubleshooting" section. I hope the new information will be enough to solve your problem. I don't want to give you the solution, I need to see if the new documentation I'm working on is efficient: it needs to scale. |
No need to fear, it's simply a pattern I don't want to encourage but that people can still use. It's not that it's going to break, it just that I find it dangerous to rely on a global CSS scope for stuff like CSS overrides. But people have been doing it for a decade with libraries like Bootstrap, so it's fine. |
Thanks for your time and seeing my reproduction repository, I'm seeing Your Merge and I find:
I do just like your code but nothing change. The issue exists still. Also, I read the css-works-on-only-on-first-load Docs, But nothing changes after your merge.
☝️ 😐 I believe you act like a great teacher, but dude, at least please answer this question in Stack Overflow or guide me. Or tell me why it happens just in |
className
did not match Server & Client)
className
did not match Server & Client)className
did not match Server and Client)
I've struggled too much, I slept 20 hours in these four days, Mayme my fatigue cause to this understanding. Or maybe I tried to vanish one of I'm confused. So confused. Definitely, the RTL Doc is not very complete. In this page just we can see a simple code, it is not very clear, Where it can be settled? Server? Client? Both? Could it be a separate component? I Don't know 😕 I wanna go back home and sleep. 😴 💤 |
@oliviertassinari, I don't know this way is proper or not, Actually, I find out using separate
It works well on both sides, server and client and makes consistent |
I also have this problem. Using Next.js with Layout _app.js component I have CustomButton component that called _app Layout (Header part) and also in the main content. This is my repro case for this issue. Its from combination from two examples : I think its not from Material UI. Its from react-jss. This maybe relevant issue But I need help. @oliviertassinari can you help me in my repo? Whats wrong with my setup. I search everything in MUI doc, jss doc, and react-jss repo. But no luck. Thanks |
I'm having the same issue and I don't know a lot to help fix it. Thanks 👍 |
@nosykretts : I think the problem is not from
So _app.js
index.js
|
@up209d , Thanks a lot, I guessed my wrapping cause to that issue, and when I omitted the wrapping and used the normal function in both sides everything became right, But thanks for your kind |
@up209d Thanks for your help and your excellent explanation. It really work without error. The problem with your solution is that the oldway next js do Layout Component. The oldway require My MainLayout is Big. It contains Header, Drawer also Heavy footer. lots of texts. Its important to my app. The new way Layout Component is layout component is supposed to imported and called inside _app.js. and I think this _app.js best new feature from NextJS. This line is from official NextJS Thanks again. |
@nosykretts In my understanding, your server-side actually renders markup content string from
When you were trying to render |
@oliviertassinari, In last docs (4.0) about SSR no any mention about createGenerateClassName and jssProvider, why? Should it be used createGenerateClassName on client/server apps? Where should I import it from, @material-ui/styles, @material-ui/core? |
It's no longer needed. You can follow the new API. |
But how to fight className mismatch in Apollo's double traversing React tree without jssProvider? |
You don't need to handle the styles in the first Apollo rendering pass. Ideally, should disable the styles generation. |
if you mean |
I don't know my issue is a bug or just a support term or just a configuration mismach, but I spend much time, Not happy go lucky writing here to somebody settle my issue. no!
I searched for 3 days, Even just sleep about 10 hours in this 3 days, try many ways, even I use Gitter but no one answer me, I see issues #10982 and #11506 and many
Stack Overflow
question and answers but I couldn't fix my issue and didn't find right way.Absolutely I read and read many times the
Material-UI
Docs but I exactly did what the Docs said.At last, I see class name hydration mismatch in server and client, 😞 this warning:
I swear I tried many ways and searched a lot. I'm using
Material-UI
version1.2.1
.This is my
Index
component as a root component:Here below you can see my
server.jsx
andclient.jsx
:So now it's needed to
template.jsx
:Ok, Now it is possible that this question is asked What is
RTL
? and Why you wrapMuiThemeProvider
inside it in both server and client?So first see
RTL
component:I saw it in
Material-UI
Docs and I believe the documentation is a little poor and could be improved. I asked myself, Why documentation pass aprops.children
for this function? and I guess maybe this function should wrap something. so I try many shapes and it works. but in the first call in browser after build. when I refresh the browser then the warning appears 😞 and I see this damn shape:Surely I wanna see below shape, but I see it just once after build:
I don't know what is going wrong. I put this question on
Stack Overflow
too. And upload a mini repo for this issue, for seeing my issue justpull
, and runnpm install
thennum run dev
. the project is accessible on localhost:4000If I break some of your rules please forgive me but guide me how I can settle this issue.
The text was updated successfully, but these errors were encountered: