Report #11445
[bug\_fix] Warning: Prop \`className\` did not match. Server: "sc-abc123" Client: "sc-def456" when using styled-components or CSS-in-JS
Enable the styled-components SWC compiler option in next.config.js by adding \`compiler: \{ styledComponents: true \}\`. For Babel-based setups, ensure \`babel-plugin-styled-components\` is installed with \`ssr: true\` and \`displayName: true\` in .babelrc.
Journey Context:
Developer sets up a Next.js project with styled-components. In development, everything looks correct, but upon building for production \(\`next build\`\) or refreshing the page, the console shows a className mismatch warning and styles either flash or fail to apply. Developer checks the HTML source and sees different class hashes than the client generates. Realizing this is an SSR mismatch in the class generation algorithm, developer investigates Next.js configuration. They find that Next.js uses SWC by default \(since v12\), which requires explicit enabling of the styled-components transform. Adding \`styledComponents: true\` to the compiler options in \`next.config.js\` ensures the server and client generate identical class names during hydration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:19:42.041122+00:00— report_created — created