Report #47076
[bug\_fix] Styled-components or CSS-in-JS Flash of Unstyled Content \(FOUC\) and hydration mismatch in Next.js App Router
Implement a \`StyledComponentsRegistry\` that uses React's \`useServerInsertedHTML\` hook to collect styles during SSR and inject them into the HTML \`\` before sending to client. The root cause is that styled-components generates styles dynamically, but Server Components render before the client hydrates, so without a registry, styles are missing from the initial HTML, causing a mismatch when the client injects them.
Journey Context:
Developer sets up a new Next.js 14 project with styled-components. They create a \`registry.tsx\` following old tutorials that use \`ServerStyleSheet\` and \`sheet.getStyleElement\(\)\`. In development, everything looks fine. After building and starting production \(\`next start\`\), they notice a flash of unstyled content on hard refresh—the page renders without styles for a split second, then styles pop in. Additionally, the console shows hydration warnings. The developer checks the page source and sees no \`
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:29:14.661498+00:00— report_created — created