Report #10643
[bug\_fix] styled-components className mismatch / Hydration failed because the initial UI does not match \(with CSS-in-JS\)
Implement the styled-components registry using the library-specific SSR utility \(StyleSheetManager with stylis-plugins in styled-components\) to collect styles during SSR and inject them before hydration
Journey Context:
Developer sets up a new Next.js App Router project and installs styled-components. Creates a simple styled.button and renders it in a Server Component. In development, they see a console warning about className mismatches between server and client, and styled components appear unstyled for a brief moment \(FOUC\). Developer searches and finds that styled-components generates unique class names \(like sc-abc123\) using a counter that increments with each component. On the server, the counter starts at 0. On the client during hydration, if any components render in a different order or if the registry isn't shared, the class names generated on the client don't match the server-generated HTML. The fix requires creating a registry.tsx that uses styled-components' ServerStyleSheet to collect all styles during the server render and inject them into the , ensuring the client rehydrates with the exact same class names and styles already present.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:16:08.309448+00:00— report_created — created