question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component styles are not inlined to the page

See original GitHub issue

Context: With Nuxt 2, bundled components in the server had matching styles that could make it possible to inline <style> tags to the HTML response of the server for faster content paint.

In Nuxt 3 and using vite, the server bundle has no information about styles but only matching chunk ids. Therefore best we could do is to add <link rel="preload" as="style"... to trigger browser prefetching styles but this is not best for performance because the network request is cascaded:

image

With Nuxt 2, with (opt-in) css-extraction, we could enable HTTP 2/Push as an alternative but well… It is dead

Another alternative is that we could somehow integrate bundle-renderer (or use a nitro render:html hook) to fetch styles (off the client public/ assets) and inline them on the fly.

Another limitation is with Component Islands (https://github.com/nuxt/framework/pull/5689) that are essentially server-side components. In order to allow components having style, we have to use a hack to use a plugin (like this) that extract styles/imports and build them to the client bundle and use prefetch links.

Ideal solution, is to make vite server build containing styles in the bundle and able to directly render them.


Remarks: Webpack 5 builder with Nuxt 3 seems actually has this information in server bundle (but we don’t use it)

image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, Oct 19, 2022

In this implementation, we inline the styles required for the first render, but subsequent navigations access CSS in separated .css files that can be cached.

1reaction
pi0commented, Aug 19, 2022

Hi dear @516310460. This issue is not dedicated to the component islands feature. Initial support of component islands in Nuxt (#5689) is static server (with props-based interactivity). In the future we plan to introduce more variants of (client) interactive islands.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - inline CSS style is not getting rendered [Previously ...
You nailed it. It's an issue with JSX. In React, any component you define must begin with a capital letter, otherwise it's assumed...
Read more >
Component styles - Angular
The Angular CLI command ng generate component defines an empty styles array when you create the component with the --inline-style flag.
Read more >
Avoiding Inline Styles for CSS Design - ThoughtCo
Inline styles don't separate content from design : Inline styles are exactly the same as embedded font and other clunky design tags that...
Read more >
Why you shouldn't use inline styling in production React apps
One of the main reasons that inline styling is not a good choice for your application is because it does not support (or...
Read more >
4. Four ways to style react components | by Agata Krzywda
In React, inline styles are not specified as a string. Instead they are specified with an object whose key is the camelCased version...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found