-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
react SSR className mismatch in production mode #14840
Comments
Do you have a minimal reproducible example? Looking at the ssr example might help you https://github.com/mui-org/material-ui/tree/next/examples/ssr |
@joshwooding I have the same configuration as the documentation you provided. I still have this problem, and it only appears in the production environment. The development environment is fine. Should I upload the project to github and attach the link address? |
@chnliquan Yes please :) |
@joshwooding https://github.com/chnliquan/react-cnode
|
@chnliquan I have tried your reproduction. It's working great on my end. |
@oliviertassinari Are you sure you are in a production environment? First use @material-ui/core v3.9.2 |
Facing similar JSS issues with SSR: One or more classnames share common styles. Please check code here: https://github.com/atulmy/hire-smart (open source project) |
Same issue here, looking for help |
You should find a solution in https://next.material-ui.com/guides/server-rendering/#troubleshooting. However, this issue is soo common, I'm going to change some architectural choices. |
I don't know if it's the same issue @oliviertassinari but I'm not the only one with unpredictable JSS injection. On hiresmart, we can see that styles are messed up (like my website, not published yet): On my side, it's when I'm mixing old school Theme with Hooks: import { createMuiTheme } from '@material-ui/core/styles'
import { makeStyles } from '@material-ui/styles'
const theme = createMuiTheme({
overrides: {
// lots of overrides here
}
})
const styles = theme => ({ ... })
const useStyles = makeStyles(...)
export { theme, styles, useStyles } <ThemeProvider theme={theme}>
<Router>
...
</Router>
</ThemeProvider> class Request extends Component {
}
export default withStyles(styles, { withTheme: true })(Request) |
@MBach Are you doing server-side rendering? |
I'm not, it's just a |
@MBach Interesting, how can we produce it? |
Actually I'm creating a repository where I'm removing everything "not critical" but I have some other deadlines until next week ... |
I experience this (or related) issue on the nextjs-next example, whereas before 4.0.0-alpha.3 everything was fine. I saw this from a fully clean checkout of the example. |
I have checked it many times, all the steps are the same as described in the documentation, or there is still this problem 😫. https://next.material-ui.com/guides/server-rendering/#troubleshooting |
You are running normally because the server failed to get the initial data, and then the client retrieved the request and re-rendered it. I also reappear on my colleague's machine, but if the initial data is taken, the rendering will appear className mismatch |
I'm also getting this warning: |
We are introducing a server-side rendering API: #15030. I hope this new API will leave very little room for error. |
Oh, by the way @oliviertassinari, I found a way to solve my bug, and maybe this issue I don't know. I had to specify an extra prop to my styles in order to put injected css at the right position: const useStyles = makeStyles(
theme => ({
drawerBase: {
width: 275,
flexShrink: 0
}, // etc...
}),
{ name: 'HookGlobalStyles', index: 2 }
) |
@oliviertassinari I want know how did you confirm the classNames of client are same to server and ensure them can't mismatch |
@0-Captain I'm not sure to follow your question. We are documenting the most common source of problems: https://material-ui.com/guides/server-rendering/#troubleshooting. |
@oliviertassinari It seems that the client's generateClassName have no relation with server's generateClassName, so how to ensure it work rightly?I have looked the solution and correct my code, but no effect. The className still mismatch when first render。 |
@0-Captain The problem is handled by #15030. Do you think that you could move to v4.0.0-alpha.6 when it's released this weekend? |
@oliviertassinari Ok, thank you |
The latest ssr-next example does not work when running production. like this |
@girlsfamily I have just tried the example. It's working fine. |
It's my fault. it's good now |
@girlsfamily what was your fix? |
try the latest ssr example. I missed cross-env NODE_ENV=production before |
|
I have this problem, where to do I add |
Can anyone explain why it |
@dallen4 As long as the client and the server use the same value for |
I have the same problem as you. How did you solve it? I really need your help. Thank you |
can't believe but it solved my issue as well! Thanks! :) |
this is amazing, i have been looking for solutions for months |
In the development environment, ssr runs normally. When running in the production environment, the page is opened for the first time. The style corresponding to the class name exists, but there is no defined css.
Expected Behavior 🤔
Current Behavior 😯
Steps to Reproduce 🕹
The development environment is normal, the production environment is rendered incorrectly for the first time, the console does not have any error or warning, and all configurations are configured according to the document. It puzzled me for two days without solving it. please help me
Context 🔦
Your Environment 🌎
The text was updated successfully, but these errors were encountered: