Report #57921
[bug\_fix] Warning: Prop className did not match \(Styled Components/Emotion hydration mismatch\)
Implement a ServerStyleSheet \(Styled Components\) or CacheProvider with createCache \(Emotion\) in the root layout to collect styles during SSR and inject them into the HTML head before hydration.
Journey Context:
Developer sets up styled-components or Emotion in a Next.js App Router project. Styles look correct on initial load, but browser console shows 'className did not match' warnings, and styles flicker or disappear after hydration \(FOUC\). Developer inspects HTML source and sees no style tags, but browser DevTools shows style tags injected by JS. Realizes the server rendered HTML without CSS, and client injected it later. Finds specific integration docs for styled-components registry. Creates a registry.tsx that uses ServerStyleSheet to collect styles during render, then injects them via style tag in head. Wraps root layout with this registry. The error disappears because the server now sends the CSS in the initial HTML, allowing React to hydrate with matching classNames and styles already present.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:42:46.424260+00:00— report_created — created