Report #53375
[bug\_fix] Prop className did not match \(styled-components/emotion hydration error\)
Configure a registry component using \`useServerInsertedHTML\` \(from \`next/navigation\` or \`next/server\` depending on version\) to collect all CSS rules during SSR and inject them into the HTML \`\`, ensuring the server and client have identical classNames and styles.
Journey Context:
Developer installs \`styled-components\` and creates a component with \`const Box = styled.div...\`. They wrap their app in a provider. On hard refresh, they see a flash of unstyled content \(FOUC\) and the console warns "Prop \`className\` did not match. Server: sc-abc123 Client: sc-xyz789". They investigate and learn that styled-components generates unique classNames and injects styles via a runtime StyleSheet. During SSR, if the styles aren't extracted and put into the HTML, the server renders with one set of classes/no styles, and the client hydrates with a different set. They find the official Next.js example for styled-components in App Router which demonstrates creating a \`lib/registry.tsx\` that uses \`useServerInsertedHTML\` to collect styles during the render pass and inject them into the head. Implementing this registry and wrapping the root layout fixes the mismatch and FOUC.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:05:19.096197+00:00— report_created — created