Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOUC with full reload #8890

Closed
7 tasks done
silveltman opened this issue Jul 2, 2022 · 4 comments
Closed
7 tasks done

FOUC with full reload #8890

silveltman opened this issue Jul 2, 2022 · 4 comments
Labels
enhancement New feature or request feat: css p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@silveltman
Copy link

silveltman commented Jul 2, 2022

Describe the bug

My css, which is imported in main.js, is automatically inline in the head of the page when running the dev server. When running vite build and vite preview, it injects a link tag.

When running de dev server I am also experiencing a Flash of unstyled content (FOUC) when the page loads. This is very annoying, since I use vite-plugin-eleventy so rebuilds are a basic part of my dev experience.

I spent a lot of time searching on the web and in the issues, but can't seem to find the problem. It doesn't seem like normal behaviour.

Disclaimer: I'm very new to vite

I made my repo public for reproduction.

Reproduction

https://github.com/silveltman/vite-reproduction

System Info

windows 11
Firefox and Chrome (I tested those 2)
Npm 8.11.0
node v16.15.1

Dependencies can be found in the github repo

Used Package Manager

npm

Logs

No response

Validations

@silveltman
Copy link
Author

I would like to add to this that it makes working with gsap scrolltrigger nearly impossible, since the absense of style cause the content to jank. Therefore, it triggers animations that are not supposed to get triggered yet

@sapphi-red
Copy link
Member

#4589 injects t=${timestamp} which changes every time hmr happens.
I suppose injecting t=${fullInitializeCount}which only change when circular dependency is detected instead of it will fix this. (Maybe #7893 could be done at the same time)

@sapphi-red sapphi-red added enhancement New feature or request p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) and removed pending triage labels Jul 3, 2022
@sapphi-red sapphi-red changed the title Css automatically inlined + FOUC FOUC with full reload Jul 8, 2022
@Pyrolistical
Copy link

Pyrolistical commented Jul 17, 2022

I ran into this as well and what is happening is because you are loading the css from javascript the browser think it can do the initial render.

You can workaround this if you can add a link to the css in the head.

Here is your repo with this change https://stackblitz.com/edit/github-9hxcqg?file=src/_includes/head.liquid

The css path is a little funky because its relative to src, not where the head.liquid file is defined.

@bluwy
Copy link
Member

bluwy commented Nov 7, 2023

I'm not sure if there's something to fix here. As Pyrolistical pointed out, you're importing CSS from JS so there's bound to be a short period before the CSS is applied. If Vite has to analyze all the imports to inline into the HTML before responding it, it makes fetching the HTML much slower. Hence the optimization is only applied in builds.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feat: css p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

No branches or pull requests

4 participants