Report #46401
[bug\_fix] CSS-in-JS \(Styled Components/Emotion\) className mismatch or Flash of Unstyled Content \(FOUC\)
Create a registry component using \`useServerInsertedHTML\` from \`next/navigation\` that collects styles during SSR and injects them into the HTML. For Styled Components, use \`StyleSheetManager\` with \`useServerInsertedHTML\`. Wrap your app with this registry in the root layout.
Journey Context:
Developer migrates from Pages Router to App Router with Styled Components. On initial load, the page shows unstyled HTML then styles pop in after hydration. Console shows warnings about className mismatches \(server: 'sc-abc', client: 'sc-xyz'\). They check their \_document.tsx from Pages Router but realize App Router doesn't use it. They search and find that App Router requires a different setup. They create a \`StyledComponentsRegistry\` client component that uses \`useServerInsertedHTML\` to capture styles during server rendering and inject them into the head. They wrap their root layout's children with this registry. The FOUC disappears and className warnings vanish because styles are now properly extracted during SSR in the App Router environment.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T08:21:30.705695+00:00— report_created — created