-
Notifications
You must be signed in to change notification settings - Fork 103
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
Vuetify with tree shake enabled in SSR doesn't render property #208
Comments
TreeShake worked when i enabled it on your example project. However, try add extractCSS to the build property. With not extracting, all of the CSS gets |
Any idea why |
@vishr Is it fixed with |
@MuhaddiMu Not sure what you are talking about, with https://github.com/nuxt-community/vuetify-module/releases/tag/v2.0.0-alpha.0 , there is no way to not use treeShaking. Vuetify is treeshakable by default and you shouldn't use |
@vishr check that - #210 (comment) |
I'm currently investigating the same issue. From what I gathered so far when using |
From my understanding if your treeShake is enabled and working correctly, extractCSS will only pull out the css from the vendor.js that your treeShake has gathered. I have a project and it is working like this for me.
I'd suggest doing a npm run build -- -a to check that the vuetify bundle is showing in your vendor.js. |
@enddevNZ Indeed, my bad, it does seem to only include the CSS for what's being used in the app, which is much better that what I first thought! |
Ok, I found a way to make it work 👍. Sadly it would require quite a few changes in Vuetify :(. Basically we first would need to change Vuetify components like so: // Name the styles import
import styles from './VCard.sass'
/* @vue/component */
export default mixins(
Loadable,
Routable,
VSheet
).extend({
// Add a beforeCreate hook that inject the styles if presents
beforeCreate() {
if(styles.__inject__) {
styles.__inject__(this.$ssrContext)
}
},
// ...
}) Then in Nuxt config you ask the /*
** Build configuration
*/
build: {
loaders: {
vueStyle: { manualInject: true }
}
} When doing so, the style get's injected in the SSR context correctly 👍. This behaviour from If This change would add that hook to every component though so it's still has a bit of a performance hit (even though it's just calling a function that immediately returns). Maybe we could find a way for that hook to be defined when running on the server? Anyway that should probably move the the Vuetify repository if we want to take this further 👍 |
@adrienbaron Well spotted ! |
@freddy38510 thanks! I think the only way for this to work is to add this hook to every Vuetify components with a PR there. I’ve asked for opinions on their discord, waiting for feedback before proceeding with doing the PR if everything looks OK for them |
@adrienbaron i talked about the style "main.sass" imported from this file. As soon as "manualInject" is enabled, all styles imported from vuetify need to be injected manually. Not only those from components. We could also use the module nuxt-purgecss to improve performance. purgeCSS: {
mode: 'postcss',
paths: [
'node_modules/vuetify/src/**/*.ts'
],
} Of course, some selectors should be whitelisted. |
@freddy38510 good shout! Yes we would need to figure something out for the main style, I didn’t see it :)! |
@adrienbaron Yeah that's right! The unused CSS is also dropped from js files. I just did a comparison with and without purged CSS on a basic template of Vuetify with a Card component in content. |
Not really. The issue still exists. |
@adrienbaron Thank for your time investigating, so from your POV it seems that it's overall Vuetify components that would have a SSR issue ? EDIT : Succeeded to reproduce it without Vuetify, but it's related of how Vuetify components are handling css (importing the css in js) : https://github.com/kevinmarrec/nuxt-css-issue |
Super lazy workaround, add to
It's a heavy-handed overkill workaround, but it prevent some massive page reflowing I was having on load, so it's a trade off of a fast load time that feels sluggish, and broken, and a slower load time that looks snappier. Combining this with |
@DispatchCommit You don't have double css ? |
@kevinmarrec No I do get duplicated CSS for some styles, so it's not ideal, but it's functional for now until we get a better a better solution for the bug you've pointed out above. |
I guys, i'm having the same problem with my web app. When i run in development the page runs well and don't take long for css styles been applied. But when when it goes to production this is what happens, the styles takes time for come then it loads well. Can anyone tell me why is having this behavior ? |
First i though it was a problem with vuetify version i tried to update it, but it didn't solve anything. I'm really needing for a solution |
@YannickSilva It's possible you have the same problem, meaning SSR doesn't include styles. I see 2 choices for now:
First you need to update your "vuetify-loader": "git+https://github.com/adrienbaron/vuetify-loader.git" Then it requires to change a bit of configuration depending on the version of Vuetify Nuxt module you are using. Here is an example export default {
// ...
build: {
loaders: {
vueStyle: { manualInject: true }
}
},
vuetify: {
treeShake: {
loaderOptions: { registerStylesSSR: true }
}
}
} For // nuxt.config.js
export default {
// ...
build: {
loaders: {
vueStyle: { manualInject: true }
}
},
vuetify: {
loader: {
registerStylesSSR: true
}
}
} Finally, when using For example like so: <!-- default.vue -->
<style lang="stylus">
@import "../assets/style/app.styl"
</style> |
@adrienbaron the problem is that i really need the SSR working because of SEO, and for the second option if isn't well tested i would go for it, so i can not have problem in the future. But i have another question if i use the Tag would it affect my page SEO ? |
@YannickSilva if you use the second option it shouldn't affect SEO :). I use it on: https://www.clashofstats.com/ if you want to checkout how it behaves |
@adrienbaron thanks, i will give it a try. Them i will tell you something, thanks for the help |
@adrienbaron i don't understand how i will install your npm package, should i copy paste your package.json or something ? There no command for installing it |
@YannickSilva basically the PR is currently open, when it's merged and a new version of "vuetify-loader": "git+https://github.com/adrienbaron/vuetify-loader.git" The update your dependencies. Your project should then use the version of |
Thanks @adrienbaron |
@adrienbaron thanks for your time in coming up with a workaround! I am trying to follow your process and make the changes in @/vue/component but it seems that such a file doesn't exist for me, I have tried looking through "component-compiler-utils" but I am not sure if that is the one... |
@JosephSaw I actually came up with another fix for this, it takes the form of an MR on Vuetify Loader, it sadly hasn’t been merged yet, but you can try to use my version if you want to: vuetifyjs/vuetify-loader#126 |
What @adrienbaron said, or you guys can include that CSS in layouts/default.vue. It always loads the CSS SSR |
@adrienbaron
vuetify: { but when I try to build I get errors:
I'm building on Windows, and it seems like it is not building the path to the sass files of vuetify's components. |
@dor272 hi! I didn’t test on Windows so it is possible 😔, the PR has been merged in the main repo but not released yet, feel free to try and fix it and open a PR for that 👍 |
@adrienbaron After some digging the generate returns error for unix systems as well. so far I was not able to fix it. |
Hum, are you sure you followed all the instructions (the |
@adrienbaron pretty sure, thats my exact config:
|
@dor272 I'm depending on Then in Nuxt config: {
// ...
buildModules: ["@nuxtjs/vuetify"],
vuetify: {
frameworkOptions: {
theme: {
disable: true,
dark: true,
},
icons: { iconfont: "mdiSvg" },
},
loader: {
registerStylesSSR: true,
},
defaultAssets: false,
customVariables: ["~/assets/style/vuetify-custom.scss"],
},
build: {
loaders: {
vueStyle: { manualInject: true },
},
}
} Here is // If you need to extend Vuetify SASS lists
@import "~vuetify/src/styles/styles.sass";
$color-pack: false;
$material-dark: map-merge(
$material-dark,
(
cards: #222222, // Grey 2
bg-color: #101010 // Grey 0
)
);
// Tabs
$tab-font-size: 0.75rem;
$tabs-item-padding: 0 8px;
$slide-group-prev-basis: 36px;
// Container
$grid-gutter: $spacer * 4;
$container-padding-x: $grid-gutter / 2;
$grid-gutters: map-deep-merge(
(
"xs": $grid-gutter / 12,
"sm": $grid-gutter / 6,
"md": $grid-gutter / 3,
"lg": $grid-gutter * 2/3,
"xl": $grid-gutter
),
$grid-gutters
);
$alert-padding: $spacer * 2;
$alert-margin: $spacer * 2;
$dialog-margin: 8px; I don't have the |
@adrienbaron I tried to create a new project. fresh install of nuxt and vuetify, upgraded
you can run lighthouse on both and see performance is pretty poor in mobile and both loading all vuetify css (either from css file or js) |
@adrienbaron any ideas? |
@adrienbaron could you clarify what is the best way of making use of your fix currently? I'm using Looking at my Update: I think I needed to do this manual setup:
After doing that, there is a noticeable change on the styles rendered server-side, but they are still not right and cause a flash of wrongly styled content before the client is hydrated. Is there anything else I should try? |
@cprcrack Your config looks on the right track 👍 ! I haven't updated my loader yet still using my fork but it should work ^^". One thing to be aware is that if you had files in the <style lang="stylus">
@import "../assets/style/app.styl"
</style> Other than that your config looks OK, I also disabled vuetify: {
frameworkOptions: {
theme: {
disable: true,
dark: true,
},
icons: { iconfont: "mdiSvg" },
},
loader: {
registerStylesSSR: true,
},
defaultAssets: false,
customVariables: ["~/assets/style/vuetify-custom.scss"],
},
build: {
loaders: {
vueStyle: { manualInject: true },
},
} |
I finally was able to fix the issue just by enabling the
Moreover by enabling extractCSS the total size of the Regarding why it fixed it, maybe it had something to do with unscoped styles that I was using in my .vue files. Update: not really, doesn't seem to make a difference. |
I toyed around with this and to get it working with current nuxt/vuetify-module v1.11.3 to config should be like this: // nuxt.config.js
export default {
// ...
build: {
loaders: {
vueStyle: { manualInject: true }
}
},
vuetify: {
treeShake: {
loaderOptions: {
registerStylesSSR: true
}
}
},
css: [
// Don't use this, it won't work if manualInject is true
],
} I feel that Lighthouse scores are slightly better with this instead build: {
extractCSS: true
} You get some small penalties for "remove unused css", but overall score is still better. |
This really needs a proper fix. When using the regular I have tried all various combinations of settings in this issue and nothing solves the issue. build: {
extractCSS: true,
loaders: {
vueStyle: {
manualInject: true,
},
},
},
vuetify: {
customVariables: ["~/assets/styles/variables.scss"],
optionsPath: "./vuetify.options.js",
treeShake: {
loaderOptions: {
registerStylesSSR: true,
},
},
}, It produces error:
|
I'm seeing the same webpack error. |
Module version
1.9.0
Describe the bug
If I enable
treeShake
the page rendered via SSR isn't display properly.To Reproduce
I have attached a sample project.
nuxtjs-vuetify.zip
Steps to reproduce the behavior:
yarn && yarn build && yarn start
curl http://localhost:3000 > /tmp/out.htm
and open to see the fileExpected behavior
The SSR version should be same as client
Screenshots
The text was updated successfully, but these errors were encountered: