Closed tobiasklemp closed 1 year ago
@tobiasklemp can you try manually going into theme.mjs
and changing:
head.addHeadObjs(computed(() => {
const style = {
children: styles.value,
type: 'text/css',
id: 'vuetify-theme-stylesheet'
};
if (parsedOptions.cspNonce) style.nonce = parsedOptions.cspNonce;
return {
style: [style]
};
}));
if (IN_BROWSER) {
watchEffect(() => head.updateDOM());
}
to:
function updateStyles() {
head.push(computed(() => {
const style = {
children: styles.value,
type: 'text/css',
id: 'vuetify-theme-stylesheet'
};
if (parsedOptions.cspNonce) style.nonce = parsedOptions.cspNonce;
return {
style: [style]
};
}))
}
if (IN_BROWSER) {
watch(styles, updateStyles, {
immediate: true
});
}
and see if that stops the memory leaks?
@Teranode Yes, that stops the memory leak.
Just FYI the latest vueuse/head is fully reactive so you shouldn't need this
if (IN_BROWSER) {
watchEffect(() => head.updateDOM());
}
@harlan-zw I don't think that would help this issue, it only runs in the browser. Is there any way to detect if the installed vueuse/head is already reactive?
I've had other problems with memory leaks from SSR, ended up doing this to fix it: https://github.com/vuetifyjs/vite-ssg/commit/ff268abe11ff225fb8e75b3b07864f5a4c074eee
@harlan-zw I don't think that would help this issue, it only runs in the browser. Is there any way to detect if the installed vueuse/head is already reactive?
Maybe related https://github.com/nuxt/nuxt/issues/15095? I'd recommend swapping computed for a computer-getter either way.
Computed getter / fully reactive is supported since 0.8.0 (https://github.com/vueuse/head/releases/tag/v0.8.0), so should be safe to use.
No guarantees though :upside_down_face:
head.addHeadObjs({
style: [
{
// you could probably just pass in styles directly as well
children: () => styles.value,
type: 'text/css',
id: 'vuetify-theme-stylesheet'
nonce: parsedOptions.cspNonce || false
}
]
})
This doesn't actually seem to be reactive anymore no matter what I do. 0.7.6 was fine, but with 1.0.26 none of these update:
head.push({
style: [{
children: styles,
id: 'vuetify-theme-stylesheet',
nonce: parsedOptions.cspNonce,
}],
})
head.push({
style: [{
children: () => styles.value,
id: 'vuetify-theme-stylesheet',
nonce: parsedOptions.cspNonce,
}],
})
head.push(() => ({
style: [{
children: styles.value,
id: 'vuetify-theme-stylesheet',
nonce: parsedOptions.cspNonce,
}],
}))
head.push(computed(() => ({
style: [{
children: styles.value,
id: 'vuetify-theme-stylesheet',
nonce: parsedOptions.cspNonce,
}],
})))
same with head.addHeadObjs
instead and adding back watchEffect(() => head.updateDOM())
Hey, the recent changes didn't do the trick. I ran my above benchmark again using vuetify 3.1.3 with the same result and i discovered that https://github.com/vuetifyjs/vuetify/blob/07098900e64d9bc639c29bb7e35b790ff13f750d/packages/vuetify/src/composables/theme.ts#L204 causes the leak. I'm not sure if these options need to be reactive, in my view these options are loaded once and i don't see how these would change after that, but maybe someone else has more insight to this.
When the parsed options are not reactive, the leak is gone for the most part.
Running my benchmark, it creates about 35K ssr requests:
I was not able to isolate the last small leak, but maybe you will be able to fix this big one.
causes the leak. I'm not sure if these options need to be reactive, in my view these options are loaded once and i don't see how these would change after that, but maybe someone else has more insight to this.
Maybe @nekosaur could provide some insight to the necessity for reactive.
The only thing I could think of was being able to provide a reactive object, but that doesn't actually work because parseThemeOptions
does a deep copy: Playground
The only thing I could think of was being able to provide a reactive object, but that doesn't actually work because
parseThemeOptions
does a deep copy: Playground
Is this solved?
We kindly ask users to not comment on closed/resolved issues. If you believe that this issue has not been correctly resolved, please create a new issue showing the regression or create a new discussion.
If you have any questions, please reach out to us in our Discord community.
Environment
Vuetify Version: 3.0.0 Vue Version: 3.2.45 Browsers: Chrome 107.0.0.0 OS: Mac OS 10.15.7
Steps to reproduce
Environment
Darwin
v16.13.2
3.0.0
1.0.0
yarn@1.22.19
vite
css
,build
,vite
-
-
Reproduction
Clone this minimal starter project: https://github.com/CodyBontecou/nuxt3-and-vuetify
do a
Then run the build with
Open the devtools and watch the memory tab.
I used k6 to run a small load test against my project:
Describe the bug
After running the test, about 160 mb of ram get stuck, indicating that something is leaking. After some investigation it appears to be related with the usage of the head composable in combination with a computed value outside of a component context.
This is the relevant code, which is causing the leak:
I found this issue which also indicates that this is a problem, but I don't know how i would be able to use vuetify during ssr.
Expected Behavior
Run without leaking memory.
Actual Behavior
It is leaking a quite significant amount of memory.
Reproduction Link
https://github.com/CodyBontecou/nuxt3-and-vuetify