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

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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

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.

Description

plugin: rsc

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

Dominant language
TypeScript
Stars
1.2k
Forks
287
Avg merge
1d 17h
Merged PRs (30d)
19

Getting set up

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.

More from vitejs/vite-plugin-react

All issues in vitejs/vite-plugin-react

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.