Subscribe on changes!

Server Side Render does not adds the css renderToString

avatar
Apr 22nd 2022

Version

3.2.33

Reproduction link

github.com

Steps to reproduce

yarn
yarn build
node index.mjs

What is expected?

<h1 class="banner">Hello Jane Doe</h1>
<style> .banner { color: red; } </style>

What is actually happening?

<h1 class="banner">Hello Jane Doe</h1>

It should render the css also along with the html

avatar
Apr 22nd 2022

Your generated code does inject the CSS into the <head> at runtime, which it does for HMR, and only because you built without NODE_ENV=production, in other words - this is a development behavior, not production behavior.

  1. Build with NODE_ENV=production
  2. which will build an individual .css file in /dist
  3. which will be included in the HTML file
  4. So all CSS styles are loaded from this file

If you want to generate critical CSS, that's outside of the scope of Vue core.

avatar
Apr 22nd 2022

Yes, but I do not want the external CSS to be generated. As I will have dynamic parameters for some styles e.g. color prop can be red, green, etc.

So I want renderToString from vue/server-renderer to give me the generated CSS also along with the HTML.

React.js does the same thing it gives the generated CSS when you render the code Server Side

avatar
May 21st 2022

hey so how did you solve the problem? i have the same problem. if HTML can not with CSS, i think @vue/server-renderer is useless for me.

avatar
May 21st 2022

I used svelte and its compiler worked perfectly for my use case.

avatar
May 22nd 2022

fine thanks