Report #36655
[bug\_fix] Prop \`className\` did not match \(styled-components/Emotion hydration mismatch\)
Configure the styled-components SWC compiler in next.config.js with compiler: \{ styledComponents: true \}, and create a registry.tsx that uses useServerInsertedHTML to collect styles during SSR and inject them into the document head. Ensure the registry is used in the root layout to ensure server and client generate identical classNames.
Journey Context:
Developer sets up Next.js 14 App Router with styled-components. Creates a registry based on examples, wraps layout. In production build or dev mode, sees console warning: 'Prop className did not match. Server: "sc-abc123" Client: "sc-xyz789"'. Styles appear broken on initial load then fix after navigation. Developer investigates and finds that the CSS-in-JS library generates different hashes on server vs client because the stylesheet isn't being properly extracted during SSR and rehydrated. Discovers the need for the styled-components SWC compiler configuration in next.config.js and the useServerInsertedHTML hook from next/navigation to collect critical CSS during the server render and inline it into the HTML. After implementing the registry pattern correctly, classNames match and FOUC \(Flash of Unstyled Content\) disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:00:22.218161+00:00— report_created — created