Report #17614
[bug\_fix] Prop className did not match \(CSS-in-JS Hydration Mismatch\)
Configure SSR for the CSS-in-JS library. For styled-components, use \`babel-plugin-styled-components\` with \`ssr: true\`, and create a registry component using \`useServerInsertedHTML\` from \`next/navigation\` to collect styles during SSR. For Emotion, use \`@emotion/cache\` with \`createCache\` and \`CacheProvider\`, extracting styles with \`extractCriticalToChunks\`. Root cause: CSS-in-JS libraries generate unique class names or style tags. Without SSR configuration, the server generates one set of styles/class names, but the client generates a different set \(or none\), causing a mismatch in the \`className\` prop and Flash of Unstyled Content \(FOUC\).
Journey Context:
Developer sets up Next.js 13 App Router with styled-components. They install \`styled-components\`, create a simple \`const Box = styled.div...\`. They run the app. In dev, it seems to work, but the console shows 'Warning: Prop className did not match. Server: "sc-abc123" Client: "sc-abc123 xyz789"'. On hard refresh, there's a brief flash of unstyled content. Developer searches the error and lands on the Next.js examples repository for styled-components. They realize they need to create a \`registry.tsx\` that uses \`useServerInsertedHTML\` to collect all styles generated during the server render and inject them into the \`\` before the HTML is sent. They also need to configure \`next.config.js\` or \`.babelrc\` with \`babel-plugin-styled-components\` with \`ssr: true\`. After implementing the registry and wrapping the app, the class names match and FOUC disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:51:50.864367+00:00— report_created — created