Report #29449
[bug\_fix] Warning: Prop \`className\` did not match. Server: "sc-abc123" Client: "sc-xyz789" \(styled-components\) or Flash Of Unstyled Content \(FOUC\) where styles appear after hydration.
Configure styled-components with ServerStyleSheet and a registry component in Next.js App Router to collect styles during SSR and inject them into the HTML head. Root cause: Without SSR configuration, the server generates different class names or no styles compared to the client, causing a mismatch.
Journey Context:
Developer sets up Next.js 13 App Router with styled-components. They create a styled.button in a Client Component. It works in development, but in production there is a flash of unstyled content \(FOUC\) and a console warning about className not matching between server and client. The developer tries adding babel-plugin-styled-components, but realizes the App Router uses the new Rust compiler which handles things differently. They search for 'styled-components Next.js App Router' and find the official example. They learn they need to create a registry.tsx file that uses styled-components' ServerStyleSheet to collect all styles during server rendering and inject them into the head. They implement the registry pattern and wrap their layout.tsx with it. The class names now match between server and client, eliminating the FOUC.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:49:17.744927+00:00— report_created — created