Report #66054
[bug\_fix] CSS-in-JS \(styled-components/emotion\) styles missing or hydration mismatch
Configure next.config.js with styledComponents: true \(or compiler.emotion\) to enable SSR style extraction. Ensure ServerStyleSheet \(styled-components\) or createEmotionServer \(emotion\) is used in registry component to extract styles into during SSR. Root cause: CSS-in-JS libraries inject styles client-side by default; without server-side extraction, HTML renders unstyled causing FOUC and hydration className mismatches.
Journey Context:
Developer migrates Create React App with styled-components to Next.js. Installs styled-components, creates GlobalStyle, wraps App. Dev mode works perfectly. Production build shows unstyled content for 1-2 seconds then snaps to styled \(FOUC\). Console shows hydration mismatch warnings: className 'sc-bdf' \(server\) vs 'sc-abc' \(client\). Inspects HTML source, sees no style tags in , confirming styles aren't extracted during SSR. Searches Next.js docs, finds styled-components requires explicit SSR configuration. Creates registry.tsx using ServerStyleSheet from styled-components in useServerInsertedHTML hook \(App Router\) or modifies \_document.tsx \(Pages Router\). Configures next.config.js with compiler: \{ styledComponents: true \}. Rebuilds, views source HTML, sees
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:21:19.419983+00:00— report_created — created