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

Styles get added both inline and by reference and precede JS files #27053

Open
TheDutchCoder opened this issue May 3, 2024 · 3 comments
Open

Comments

@TheDutchCoder
Copy link
Contributor

TheDutchCoder commented May 3, 2024

Environment


  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-kz3fe2?file=components%2FMyComponent.vue

Describe the bug

When using scoped CSS (might also be without scoped, haven't tried), there's a problem after building:

  1. The CSS for the component gets added inline and as a <link>
  2. All the CSS files are declared before the JS files, instead of after (in Nuxt 2 JS files came first, so the browser can start loading them async).

#2 is not a direct problem, because browsers don't wait for the CSS to load in order to start loading JS, but since the JS is preloaded, it might still be better to hoist them above CSS?

Additional context

We discovered this while profiling our project in production and saw some odd results from Lighthouse, complaining about render blocking CSS.

We then noticed that almost all of the CSS was loaded twice (once inline, and once through <link>s).
The order was also reversed from Nuxt 2, even though that might not be so much of a bug.

Comparing the Lighthouse feedback from Nuxt 2 to Nuxt 3 (in our prod app), a few things are striking:

  • In Nuxt3: all the stylesheets are marked as "A late network request adjusted the page layout", whereas in Nuxt 2 this doesn't happen.
  • None of the css files are marked as preload in Nuxt 3, whereas they are in Nuxt 2

Logs

No response

Copy link

stackblitz bot commented May 3, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@dsvgl
Copy link

dsvgl commented May 3, 2024

related: #18376

@cogniocode
Copy link

Any update on this? Loading styles twice is not working good on SEO performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants