Skip to content

Commit

Permalink
bug: bug(mixin): fix SSR memory leak by moving subscribeDataChanging …
Browse files Browse the repository at this point in the history
…calls into beforeMount (#572) by @Pindar

Signed-off-by: Simon Dittlmann <[email protected]>
  • Loading branch information
Pindar authored and kazupon committed Apr 30, 2019
1 parent 48e3500 commit 32b5795
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand All @@ -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
}
Expand Down

0 comments on commit 32b5795

Please sign in to comment.