Skip to content

[3.x] Fix FOUC during SSR development#2911

Merged
pascalbaljet merged 3 commits into
3.xfrom
ssr-fouc-fix
Feb 25, 2026
Merged

[3.x] Fix FOUC during SSR development#2911
pascalbaljet merged 3 commits into
3.xfrom
ssr-fouc-fix

Conversation

@pascalbaljet
Copy link
Copy Markdown
Member

During SSR development, Vite normally injects CSS via JavaScript on the client side. The server-rendered HTML arrives before any JS executes, causing a flash of unstyled content (FOUC). This is particularly noticeable when using CSS frameworks or component-scoped styles.

This PR traverses Vite's SSR module graph starting from the entry point to collect all CSS dependencies, then generates <link> tags that are prepended to the head array returned by the SSR render. The tags include data-vite-dev-id attributes so Vite's client-side JS can deduplicate them and avoid injecting duplicate <style> tags.

This only applies during development. In production, Vite's build process already handles CSS extraction correctly.

@pascalbaljet pascalbaljet merged commit 2c8a40e into 3.x Feb 25, 2026
@pascalbaljet pascalbaljet deleted the ssr-fouc-fix branch February 25, 2026 09: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