Report #16537
[bug\_fix] Warning: Prop \`className\` did not match. Server: "sc-xxx" Client: "sc-yyy" \(Styled Components/Emotion hydration mismatch\)
Implement a Registry component using the CSS-in-JS library's SSR API \(e.g., \`ServerStyleSheet\`\) and inject styles using \`useServerInsertedHTML\` from \`next/navigation\`. Root cause: CSS-in-JS libraries generate styles dynamically during render; without capturing these styles on the server and sending them to the client before hydration, the client generates different class names or missing styles, causing a mismatch.
Journey Context:
Developer sets up Styled Components in a Next.js App Router project. They create a simple styled button. On page load, the button appears unstyled for a moment \(FOUC\), then styles apply. Console shows 'Prop className did not match'. Developer investigates and learns that App Router uses React 18 Streaming SSR, which requires a specific registry pattern. They create a \`registry.tsx\` that uses \`styled-components\` \`ServerStyleSheet\` to collect styles during rendering, and uses Next.js's \`useServerInsertedHTML\` to inject the style tags into the HTML. They wrap the root layout children with this registry. The hydration mismatch disappears because the server now sends the correct style tags in the initial HTML.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:53:12.324018+00:00— report_created — created