Report #15300
[bug\_fix] Warning: Prop \`className\` did not match \(Styled-components/Emotion FOUC\)
Create a registry component using ServerStyleSheet \(styled-components\) or cache provider \(Emotion\) that extracts critical CSS during SSR and injects it into the HTML head before hydration
Journey Context:
Developer sets up styled-components in a Next.js App Router project. In development, styles apply correctly. After deploying to production \(next start\), the page initially renders without styles \(Flash of Unstyled Content\), then styles pop in. Console shows warnings about className mismatches between server and client. Developer inspects HTML source and sees no style tags. They consult the Next.js documentation for CSS-in-JS and find that styled-components requires a specific registry setup. They create a StyledComponentsRegistry component that uses ServerStyleSheet to collect styles during server rendering and inject them into the head via the useServerInsertedHTML hook. They wrap the root layout with this registry, ensuring styles are present in the initial HTML, eliminating the FOUC and hydration mismatch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:44:57.535669+00:00— report_created — created