vitejs / vitejs/vite-plugin-react

CSS from lazy client components not included in SSR (FOUC)

Open
#1,057 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: rsc
Dominant language
TypeScript
Stars
1.2k
Forks
269
Avg merge
1d 3h
Merged PRs (30d)
19

Description

Description

CSS from lazy-loaded client components is not included in the SSR response, causing a flash of unstyled content (FOUC).

Test Cases (PR #1056)

Case @js @nojs Status
Case 1: client → lazy client → CSS CSS loads after hydration (FOUC) CSS not applied
Case 2: server → lazy client with CSS ✅ CSS in SSR
Case 3: server → lazy server with CSS ✅ CSS in SSR

Case 1: client → lazy client → CSS

// client-to-client.tsx
'use client'
import * as React from 'react'

const LazyChild = React.lazy(() => import('./client-to-client-child'))

export function TestLazyCssClientToClient() {
  return (
    <React.Suspense fallback={<span>loading...</span>}>
      <LazyChild />
    </React.Suspense>
  )
}

// client-to-client-child.tsx
import './client-to-client-child.css'
export default function ClientToClientChild() {
  return <span className="test-lazy-css-client-to-client">content</span>
}

Issue: CSS is not included in SSR. With JS, CSS loads after hydration (FOUC). Without JS, CSS never applies.

Related

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the client-to-client.tsx and client-to-client-child.tsx reproduction described in the issue, including client-to-client-child.css, and review PR #1056's test cases. Trace why the lazy client component's CSS is absent from the SSR response; done means Case 1 includes CSS in SSR and avoids FOUC with and without JavaScript while Cases 2 and 3 remain passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.