Report #9257
[bug\_fix] Prop \`className\` did not match. Server: "sc-xxx" Client: "sc-yyy" \(styled-components/emotion hydration mismatch\)
Use styled-components Registry in App Router \(or custom \_document in Pages Router\) to collect and inject critical CSS during SSR, ensuring consistent class naming
Journey Context:
Developer adds styled-components to a Next.js App Router project. Creates a styled component and renders it. On page load, styles are missing initially then appear \(FOUC\), or console shows className mismatch between server and client. Developer learns that styled-components generates unique class names via a hashing algorithm, and without proper SSR configuration, the server and client generate different hashes \(or no styles are extracted server-side\). Discovers the styled-components registry pattern for Next.js App Router: creating a registry component that uses React cache to collect styles during render and inject them into the document head via the head.js or layout metadata. This ensures the HTML arrives with styles already injected, preventing hydration mismatches.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:43:53.513642+00:00— report_created — created