From 32b57952b47b5698a71b359f14665011ccffe3d1 Mon Sep 17 00:00:00 2001 From: Simon Dittlmann <131621+Pindar@users.noreply.github.com> Date: Tue, 30 Apr 2019 10:56:04 +0200 Subject: [PATCH] bug: bug(mixin): fix SSR memory leak by moving subscribeDataChanging calls into beforeMount (#572) by @Pindar Signed-off-by: Simon Dittlmann <131621+Pindar@users.noreply.github.com> --- src/mixin.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/mixin.js b/src/mixin.js index 7ab5f7b64..42e9ce31f 100644 --- a/src/mixin.js +++ b/src/mixin.js @@ -28,8 +28,6 @@ export default { } this._i18n = options.i18n this._i18nWatcher = this._i18n.watchI18nData() - this._i18n.subscribeDataChanging(this) - this._subscribing = true } else if (isPlainObject(options.i18n)) { // component local i18n if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) { @@ -59,8 +57,6 @@ export default { this._i18n = new VueI18n(options.i18n) this._i18nWatcher = this._i18n.watchI18nData() - this._i18n.subscribeDataChanging(this) - this._subscribing = true if (options.i18n.sync === undefined || !!options.i18n.sync) { this._localeWatcher = this.$i18n.watchLocale() @@ -73,11 +69,33 @@ export default { } else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) { // root i18n this._i18n = this.$root.$i18n - this._i18n.subscribeDataChanging(this) - this._subscribing = true } else if (options.parent && options.parent.$i18n && options.parent.$i18n instanceof VueI18n) { // parent i18n this._i18n = options.parent.$i18n + } + }, + + beforeMount (): void { + const options: any = this.$options + options.i18n = options.i18n || (options.__i18n ? {} : null) + + if (options.i18n) { + if (options.i18n instanceof VueI18n) { + // init locale messages via custom blocks + this._i18n.subscribeDataChanging(this) + this._subscribing = true + } else if (isPlainObject(options.i18n)) { + this._i18n.subscribeDataChanging(this) + this._subscribing = true + } else { + if (process.env.NODE_ENV !== 'production') { + warn(`Cannot be interpreted 'i18n' option.`) + } + } + } else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) { + this._i18n.subscribeDataChanging(this) + this._subscribing = true + } else if (options.parent && options.parent.$i18n && options.parent.$i18n instanceof VueI18n) { this._i18n.subscribeDataChanging(this) this._subscribing = true }