Report #6725
[bug\_fix] Warning: Prop className did not match. Server: "sc-bczRLJ" Client: "sc-gsnTZi" with styled-components or emotion
Implement a StyledComponentsRegistry \(or StyleRegistry for emotion\) using React.cache and the styled-components ServerStyleSheet, wrapping the children in the root layout. Root cause: CSS-in-JS libraries generate random class names; without a registry, server and client generate different hashes, causing hydration mismatch and missing styles on initial load.
Journey Context:
Developer migrates a project using styled-components to Next.js 13 App Router. They configure the SWC plugin in next.config.js. On loading the page, they see a flash of unstyled content \(FOUC\) and console warnings: "Prop className did not match. Server: sc-abc123 Client: sc-xyz789". They check the HTML source and see the server injected styles, but the client generates different class names. Searching reveals that styled-components needs a registry to extract styles during SSR and pass them to the client. They create a lib/registry.tsx that uses styled-components' ServerStyleSheet and StyleSheetManager, then wrap the root layout's children with it. The class names now sync and FOUC disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:46:46.780391+00:00— report_created — created