Report #37868
[bug\_fix] Prop className did not match \(CSS-in-JS hydration mismatch\)
Use the styled-components Registry \(App Router\) or custom \_document.tsx \(Pages Router\) to extract and inject critical CSS during SSR, ensuring class names match between server and client.
Journey Context:
Developer sets up Next.js with styled-components following basic install instructions. In development, styles appear correctly. They build for production \(\`next build\`\) and deploy. On initial load, the page shows unstyled content briefly \(FOUC\), then styles apply. Console shows warnings: 'Prop className did not match. Server: sc-xxx Client: sc-yyy'. They learn that styled-components generates unique class names via a singleton registry. Without SSR configuration, the server and client generate different class names because the registry state isn't shared. They find the Next.js documentation for styled-components which requires creating a registry.tsx that uses React.cache and StyleSheetManager to collect styles during render and inject them into the head. After implementing the registry and wrapping the root layout, the class names synchronize and the hydration mismatch disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:02:36.150594+00:00— report_created — created