Anber / wyw-in-js

MIT License
191 stars 8 forks source link

SSR flickering in Vite Dev mode #78

Open chin2km opened 2 months ago

chin2km commented 2 months ago

Description

In Vite Dev mode for react server-side rendered application the critical CSS needed for styling the application only loads after a while after the vite runtime is loaded and the application is finished hydration.

This results in very bad flickering of UI in big applications since time to load the Vite runtime and hydration can take few seconds.

This is only an issue in dev mode of the plugin, in production mode it works perfectly where it extracts the css to a file and is inlined in the out html.

Reproducible Demo

https://github.com/chin2km/linaria-vite-dev-ssr-issue

Screenshot 2024-04-24 at 2 16 23 AM

goes to the below state after some time

Screenshot 2024-04-24 at 2 05 49 AM

Environment

Node: 20 Bundler: Vite 5 Linaria Version: 6.1.0 OS: macOS

Expectation

The linaria styles are extracted to css file and is either:

chin2km commented 2 months ago

Also created an issue in https://github.com/callstack/linaria repo since I was not sure where this should be solved. https://github.com/callstack/linaria/issues/1404