Skip to content

Fix FOUC by inlining styled-jsx styles during SSR - #84

Merged
TimoStaudinger merged 1 commit into
mainfrom
claude/styled-jsx-ssr-registry
Aug 22, 2026
Merged

Fix FOUC by inlining styled-jsx styles during SSR#84
TimoStaudinger merged 1 commit into
mainfrom
claude/styled-jsx-ssr-registry

Conversation

@TimoStaudinger

Copy link
Copy Markdown
Owner

What

On page load, the homepage flashed unstyled content: the profile image painted at its natural full size before snapping to 120px, and the social icons started small and "grew" once styles applied.

The components use styled-jsx, but with the App Router those styles are only injected at client-side hydration unless a style registry is set up — so the server-rendered HTML contained no component CSS.

This adds the official Next.js styled-jsx registry pattern:

  • New src/app/registry.tsx: a StyledJsxRegistry client component that collects styled-jsx styles during server rendering and injects them into the streamed HTML via useServerInsertedHTML
  • src/app/layout.tsx: wraps {children} in the registry

This fixes the flash site-wide for all styled-jsx components, not just the homepage.

Verification

  • Server-rendered HTML (dev and prerendered .next/server/app/index.html) now contains the styled-jsx rules inline, so the first paint is fully styled
  • yarn build passes; page renders correctly with no console errors
  • yarn test: 38 passed. The two mobile visual-snapshot failures are pre-existing on the test machine (identical failures on unmodified main; font antialiasing drift from a newer local Chromium vs the snapshot baseline) and unrelated to this change

@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
timostaudinger-com Ready Ready Preview Aug 22, 2026 12:27am

@TimoStaudinger
TimoStaudinger merged commit 1ca84a9 into main Aug 22, 2026
4 checks passed
@TimoStaudinger
TimoStaudinger deleted the claude/styled-jsx-ssr-registry branch August 22, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant