Report #92168
[bug\_fix] Warning: Prop \`className\` did not match. Server: "sc-bdfBQB" Client: "sc-gsTCUz" \(Styled-components or Emotion hydration mismatch\)
Configure a ServerStyleSheet in the Next.js registry to collect all CSS rules during SSR and inject them into the HTML head before sending to the client. In App Router, implement the styled-components registry pattern using React.cache.
Journey Context:
Developer adds styled-components to a Next.js 14 App Router project. They create a simple styled.button and render it in the root layout. In development, they notice a brief flash of unstyled content \(FOUC\) on hard refresh, and the console shows hydration warnings about className mismatches. Inspecting the page source reveals no critical CSS in the head. Developer realizes that styled-components generates different class hashes on server vs client because the server isn't collecting the styles to send with the initial HTML. They search for "styled-components nextjs app router" and find the official example. They create a registry.tsx that uses React.cache to create a ServerStyleSheet singleton, collects styles during the render, and injects them via a style tag using next/script. After implementing this registry in layout.tsx, the FOUC disappears and hydration errors are resolved because the server now sends the exact CSS needed for the initial render.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:17:48.347910+00:00— report_created — created