In my NextJS React app when i change something in the code, the HMR works and shows the correct update but if I refresh the page, this error comes up again. This happens on dev mode. Noticed where are a lot of topics with this error, tried all day different configuration setups with no effort.
Please help me to get rid of the error.
Error:
Warning: Prop
className
did not match. Server: "sc-cBoprd hjrjKw" Client: "sc-iCoHVE daxLeG"
Using "babel-plugin-styled-components": "1.11.1"
Files that can be related to the issue:
_App.tsx
function MyApp({ Component, pageProps, mainController }) {
return (
<ConfigurationProvider configuration={configuration}>
<ThemeProvider theme={mainController.getTheme()}>
<Normalize />
<Font />
<Component {...pageProps} controller={mainController} />
</ThemeProvider>
</ConfigurationProvider>
);
}
export default appControllerContext(MyApp);
_document.tsx
import Document from 'next/document'
import { ServerStyleSheet } from 'styled-components'
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet()
const originalRenderPage = ctx.renderPage
try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) =>
sheet.collectStyles(<App {...props} />),
})
const initialProps = await Document.getInitialProps(ctx)
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
),
}
} finally {
sheet.seal()
}
}
}
.babelrc
{
"presets": [
"next/babel"
],
"plugins": [
[
"babel-plugin-styled-components",
{
"ssr": true,
"displayName": true,
"preprocess": false
}
]
]
}