-
-
Notifications
You must be signed in to change notification settings - Fork 362
SSR Memory Leak with Legacy API #920
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
Comments
@DoubleJ-G
As your mentioned, I think that the lifecycle of vue has an effect too. |
I'm having the same issue, but it's not fixed even using the legacy: false option. |
I created this reproduction repo with the latest version and legacy api disabled. |
@kazupon is there any update on this? we are also experiencing the same problem with vite-plugin-ssr and legacy: false |
@ivannkf @DoubleJ-G did you figure out a way around this? |
is this not expected to be fixed anytime soon I assume? |
Just a bit of follow up. Was concerned by a memory leak on my side as well. Toggled off "globalInjection" in the vue-i18n plugin and had to import the The only downside is that I had to recheck every single component/page/layout to replace those global $t with the For the record, I'm using Nuxt 3, and Nuxt 3 is creating new plugins for each requests. Global Injection seems to be kept alive, while components instances are destroyed. That's why this seems to be working. My Nuxt plugin configuration :
Update : |
@GaetanWi unfortunately we are already using these settings and it still blows up our memory. I'm using this with https://github.com/brillout/vite-plugin-ssr |
@GaetanWi I'm using the exact same config, when I disable the I18n plugin, no leak. But when I stress test with the plugin activated, my memory goes boom. My global injection setting is already turned off. |
@chemeng I'm not using vite-plugin-ssr so I could not help sorry :/ Maybe there is something like that to do for i18n that allows you to drop useless listeners ? @brokenfiles any chance on getting your nuxt config ? How do you use your translation module ? Calling useI18n properly ? |
Hello, after further research, I found that the problem was indeed with vue-i18n and my installation. But I couldn't find any difference between my Nuxt installation and the doc. I managed to solve the problem by installing the module (still in beta) recommended by Nuxt (https://nuxt.com/modules/i18n). Here is my old import { resolve } from 'path';
import { defineNuxtConfig } from 'nuxt/config';
const r = (p: string) => resolve(__dirname, p);
export default defineNuxtConfig({
modules: ['@nuxtjs/tailwindcss', '@pinia/nuxt', '@nuxt/image-edge'],
css: ['assets/scss/layout.scss'],
app: {
head: {
....
}
},
plugins: [{ src: '~/plugins/auth/index.server.ts', mode: 'server' }],
runtimeConfig: {
public: {
....
},
},
build: {
transpile: ['@vuepic/vue-datepicker', 'chart.js'],
},
nitro: {
prerender: {
routes: ['/sitemap.xml', '/robots.txt'],
},
},
vite: {
esbuild: {
tsconfigRaw: '{}',
},
resolve: {
alias: {
'~': r('.'),
'~/': r('./'),
'~~': r('.'),
'~~/': r('./'),
'@@': r('.'),
'@@/': r('./'),
assets: r('./assets'),
public: r('./public'),
'public/': r('./public/'),
},
},
},
}); Here my old import { createI18n } from 'vue-i18n';
import { DEFAULT_LOCALE } from '@intlify/core-base';
import { defineNuxtPlugin, useCookie } from '#imports';
import en from '~/locales/en';
import fr from '~/locales/fr';
import es from '~/locales/es';
import it from '~/locales/it';
import de from '~/locales/de';
import ptBr from '~/locales/pt-br';
import { getBrowserLocale } from '~/composables/i18n/useBrowserLocale';
type MasterSchema = typeof fr;
export const AVAILABLE_LOCALES = [
'fr',
'en',
'es',
'it',
'de',
'pt-br',
] as const;
export type AvailableLocale = typeof AVAILABLE_LOCALES[number];
export const I18N_COOKIE_KEY = 'i18n.locale';
export const MASTER_LOCALE_NAME: AvailableLocale = 'en';
export default defineNuxtPlugin(({ vueApp }) => {
const defaultLocale = getBrowserLocale() ?? DEFAULT_LOCALE;
const inOneYear = new Date();
inOneYear.setFullYear(inOneYear.getFullYear() + 1);
const localeCookie = useCookie(I18N_COOKIE_KEY, {
expires: inOneYear,
});
// Set the default locale in cookies
if (!localeCookie.value) localeCookie.value = defaultLocale;
const i18n = createI18n<[MasterSchema], AvailableLocale>({
legacy: false,
globalInjection: true,
fallbackLocale: MASTER_LOCALE_NAME,
locale: locale ?? defaultLocale,
missingWarn: false,
fallbackWarn: false,
messages: {
fr,
en,
es,
it,
de,
'pt-br': ptBr,
},
});
vueApp.use(i18n);
}); For the fix, I added the i18n-module mentioned earlier. i18n: {
vueI18n: './i18n.config.ts',
locales: ['fr', 'en', 'es', 'it', 'de', 'pt-br'],
strategy: 'no_prefix',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n.locale',
redirectOn: 'root',
},
}, And finally the export default defineI18nConfig(() => {
return {
legacy: false,
globalInjection: false,
fallbackLocale: DEFAULT_LOCALE,
fallbackWarn: false,
missingWarn: false,
messages: {
en,
fr,
es,
it,
de,
'pt-br': ptBr,
},
};
}); I hope this helps if people are in the same situation as me. |
Well, I had a small leak also and this was the case. Switching to the nuxt plugin. @brokenfiles in addition to your message, the plugin is in his first release candidate since yesterday |
I believe also that with a global registration, the globalInjection is viable. |
Hi there! I fixed this issue with your tips. |
Im also facing memory leaks in SSR, trying out v9.3.0-beta.25 as we speak
|
It doesn't look it fixed it for me. |
@brokenfiles same here, I don't use globalInjection at all. |
@brokenfiles the after is with v9.3.0-beta.25? What is your globalInjection and legacy setting? |
No, before. #1479 seems to clean the $i18n object after unmount, but if the Update: I miss understood your question "the after is with v9.3.0-beta.25?" |
I have globalInjection true and legacy true (because I have a mixed setup with script setup and Options API) I did a new deploy with v9.3.0-beta.25 at the line. Maybe early to say, but it looks like it's gonna stabilise. (before the line, I commented some parts of the app, to debug) |
I'll try a stress test with the new release to see if it's fixed |
Im not using Nuxt, im using our in house created SSR package https://github.com/bistroo/vue-ssr |
It's not stable. As you can see, after a period it seems to consume memory sadly... |
This is maybe why you doesn't have the issue. For the test, I used the Here's my results (remember that I'm using Nuxt3) : As you can see, the first snapshot is normal, about 30mb, but after the stress test, the memory explodes and stays high. Here's the siege results : ![]() I think the issue is not closed yet. Update: after your last message, you seems to still have the issue! |
@brokenfiles yep, the issue still exists sadly... |
Im going the replace every injected |
Thank you for your reproduction Your case was not set up for a proudction build in vite. Therefore, the code for vue-devtools is installed. |
Hi! all I was a bit confused by this current issue as there are multiple cases reported. 😅 If this occurs in the |
We have faced memory leaks in SSR as well. ![]() I noticed that disabling @nuxtjs/[email protected] helped. The solution is weird but works for us: |
If any of you is still able to reproduce this leak using the latest version of I have tried updating the older reproductions provided here without any luck, I would be happy to take a good look at the memory leak if it still occurs! So far I have been able to eliminate some of the memory leaks in |
@BobbieGoede I am also experiencing issues with memory leaks, which started occurring when I updated my project to the latest Vue/Vite version using Quasar. I also had to update I tried to make a reproduction for this and found out that it does not seem to be Probably it has something to do with using the ESM version of this package, as the new project that has the issue is bundled as ESM and the previous one as CommonJS. Repo for version without memory leak: https://github.com/Evertvdw/memory-leak-quasar-v1 Repo for version with memory leak: https://github.com/Evertvdw/memory-leak-quasar-v2 These repos contain a readme with some instructions/steps for the reproduction. |
I just tried the beta version 10 and the issue mentioned above seems to be fixed there. So that is great :) |
@Evertvdw Since version 10 reduces the codebase I hope that makes it somewhat easier to debug memory leaks if they do pop up again 🙏 |
Reporting a bug?
Using
vite-plugin-ssr
to run Vue 3 with server side rendering, leaving the legacy api enabled will cause memory to slowly increase with every request.Expected behavior
Memory does not unexpectedly keep increasing.
Reproduction
I have reproduced a minimal example here https://github.com/DoubleJ-G/vue-i18n-memory-leak
I have also created a branch
legacy-disabled
to demonstrate the issue does not happen with it disabled.System Info
Screenshot
Running 20,000 requests with legacy enabled:

Running 20,000 requests with legacy disabled:

Additional context
From some memory debugging I pinned it down to vue-i18n.cjs.js line 1549 which is the
beforeCreate()
hook. I could not pin point it further, but if I comment out the hook the issue also seems to be resolved. I believe this may be an issue because Vue docs stateunmounted()
is not called on the server side, which seems to be were the cleanup should run.Validations
The text was updated successfully, but these errors were encountered: