Skip to content
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

Warning: Prop className did not match. Server generate classes ID difference than Client classes ID #28508

Closed
1 task
nurbeknurjanov opened this issue Sep 21, 2021 · 5 comments
Labels
status: waiting for author Issue with insufficient information

Comments

@nurbeknurjanov
Copy link

Material Ui 5 version has problem with SSR

Here is error:

Warning: Prop className did not match. Server generate classes ID difference than Client classes ID

But it doesn't help for Mui 5 version.
It helps to Mui 4 version.
But not to Mui 5 version.

Here is example of code

const style = (theme)=>{
return {
example: {
//background: 'yellow' , //this works
background: props => props.bgColor ? props.bgColor: 'yellow' , //this doesn't work
},
};
};
const StyledButton = withStyles(style)(
({classes, bgColor, ...props})=><Button className={classes.example} {...props}/>
);

It works fine if I don't use props like bgColor.
If here is background:'yellow'

But if there is props condition like this
background: (props:BgColorType) => props.bgColor ? props.bgColor: 'yellow' , //this doesn't work

@nurbeknurjanov nurbeknurjanov added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 21, 2021
@nurbeknurjanov
Copy link
Author

I have tried this as you recommend

MyDocument.getInitialProps = async (ctx) => {

const originalRenderPage = ctx.renderPage;
const cache = createEmotionCache();
const { extractCriticalToChunks } = createEmotionServer(cache);

ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) => <App emotionCache={cache} {...props} />,
});

const initialProps = await Document.getInitialProps(ctx);
const emotionStyles = extractCriticalToChunks(initialProps.html);
const emotionStyleTags = emotionStyles.styles.map((style) => (
<style
data-emotion={${style.key} ${style.ids.join(' ')}}
key={style.key}
dangerouslySetInnerHTML={{ __html: style.css }}
/>
));

return {
...initialProps,
styles: [...React.Children.toArray(initialProps.styles), ...emotionStyleTags],
};
};

But this doesn't help for Mui 5 version

@mnajdova
Copy link
Member

But it doesn't help for Mui 5 version.
It helps to Mui 4 version.
But not to Mui 5 version.

It's hard to follow what you mean by this. Do you see the error in v5 or v4? If it is happening in v4 it is likely duplicate. See #26876

@mnajdova mnajdova added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 21, 2021
@nurbeknurjanov
Copy link
Author

But it doesn't help for Mui 5 version.
It helps to Mui 4 version.
But not to Mui 5 version.

It's hard to follow what you mean by this. Do you see the error in v5 or v4? If it is happening in v4 it is likely duplicate. See #26876

No, the error happens in v5.
v4 is ok.

And your suggestion for v5 https://github.com/mui-org/material-ui/tree/master/examples/nextjs, it doesn't help.
Error is still there, even if I try example of next for v5.

Am I managed to explain ??

@nurbeknurjanov
Copy link
Author

To Arseny, yes it is, it is a dupplicate of bug of this open ticket
#27512

Here is a sandbox example to see the bug

https://codesandbox.io/s/charming-rain-oswex?file=/pages/index.js

@eps1lon
Copy link
Member

eps1lon commented Oct 11, 2021

Closing in favor of #27512

@eps1lon eps1lon closed this as completed Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

3 participants