Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit 32b5795

Browse files
Pindarkazupon
authored andcommittedApr 30, 2019
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>
1 parent 48e3500 commit 32b5795

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed
 

‎src/mixin.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export default {
2828
}
2929
this._i18n = options.i18n
3030
this._i18nWatcher = this._i18n.watchI18nData()
31-
this._i18n.subscribeDataChanging(this)
32-
this._subscribing = true
3331
} else if (isPlainObject(options.i18n)) {
3432
// component local i18n
3533
if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
@@ -59,8 +57,6 @@ export default {
5957

6058
this._i18n = new VueI18n(options.i18n)
6159
this._i18nWatcher = this._i18n.watchI18nData()
62-
this._i18n.subscribeDataChanging(this)
63-
this._subscribing = true
6460

6561
if (options.i18n.sync === undefined || !!options.i18n.sync) {
6662
this._localeWatcher = this.$i18n.watchLocale()
@@ -73,11 +69,33 @@ export default {
7369
} else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
7470
// root i18n
7571
this._i18n = this.$root.$i18n
76-
this._i18n.subscribeDataChanging(this)
77-
this._subscribing = true
7872
} else if (options.parent && options.parent.$i18n && options.parent.$i18n instanceof VueI18n) {
7973
// parent i18n
8074
this._i18n = options.parent.$i18n
75+
}
76+
},
77+
78+
beforeMount (): void {
79+
const options: any = this.$options
80+
options.i18n = options.i18n || (options.__i18n ? {} : null)
81+
82+
if (options.i18n) {
83+
if (options.i18n instanceof VueI18n) {
84+
// init locale messages via custom blocks
85+
this._i18n.subscribeDataChanging(this)
86+
this._subscribing = true
87+
} else if (isPlainObject(options.i18n)) {
88+
this._i18n.subscribeDataChanging(this)
89+
this._subscribing = true
90+
} else {
91+
if (process.env.NODE_ENV !== 'production') {
92+
warn(`Cannot be interpreted 'i18n' option.`)
93+
}
94+
}
95+
} else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
96+
this._i18n.subscribeDataChanging(this)
97+
this._subscribing = true
98+
} else if (options.parent && options.parent.$i18n && options.parent.$i18n instanceof VueI18n) {
8199
this._i18n.subscribeDataChanging(this)
82100
this._subscribing = true
83101
}

0 commit comments

Comments
 (0)
This repository has been archived.