mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-25 09:10:33 +03:00
fix: workaround for memoryleak in destroyed hook
This commit is contained in:
+20
-14
@@ -29,7 +29,10 @@ export default function createMixin (Vue, options) {
|
||||
// Add a marker to know if it uses metaInfo
|
||||
// _vnode is used to know that it's attached to a real component
|
||||
// useful if we use some mixin to add some meta tags (like nuxt-i18n)
|
||||
if (!isUndefined(this.$options[options.keyName]) && this.$options[options.keyName] !== null) {
|
||||
if (isUndefined(this.$options[options.keyName]) || this.$options[options.keyName] === null) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.$root._vueMeta) {
|
||||
this.$root._vueMeta = { appId }
|
||||
appId++
|
||||
@@ -62,7 +65,8 @@ export default function createMixin (Vue, options) {
|
||||
// when it changes (i.e. automatically handle async actions that affect metaInfo)
|
||||
// credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux)
|
||||
ensuredPush(this.$options, 'created', () => {
|
||||
this.$watch('$metaInfo', function () {
|
||||
this.$watch('$metaInfo', () => {
|
||||
this.__metaInfo = undefined
|
||||
triggerUpdate(this, 'watcher')
|
||||
})
|
||||
})
|
||||
@@ -126,33 +130,35 @@ export default function createMixin (Vue, options) {
|
||||
}
|
||||
|
||||
// do not trigger refresh on the server side
|
||||
if (!this.$isServer) {
|
||||
if (this.$isServer) {
|
||||
return
|
||||
}
|
||||
|
||||
// no need to add this hooks on server side
|
||||
updateOnLifecycleHook.forEach((lifecycleHook) => {
|
||||
ensuredPush(this.$options, lifecycleHook, () => triggerUpdate(this, lifecycleHook))
|
||||
})
|
||||
},
|
||||
// TODO: move back into beforeCreate when Vue issue is resolved
|
||||
destroyed () {
|
||||
// do not trigger refresh:
|
||||
// - on the server side
|
||||
// - when the component doesnt have a parent
|
||||
// - doesnt have metaInfo defined
|
||||
if (this.$isServer || !this.$parent || !hasMetaInfo(this)) {
|
||||
return
|
||||
}
|
||||
|
||||
// re-render meta data when returning from a child component to parent
|
||||
ensuredPush(this.$options, 'destroyed', () => {
|
||||
// Wait that element is hidden before refreshing meta tags (to support animations)
|
||||
const interval = setInterval(() => {
|
||||
if (this.$el && this.$el.offsetParent !== null) {
|
||||
/* istanbul ignore next line */
|
||||
return
|
||||
}
|
||||
|
||||
clearInterval(interval)
|
||||
|
||||
if (!this.$parent) {
|
||||
/* istanbul ignore next line */
|
||||
return
|
||||
}
|
||||
|
||||
triggerUpdate(this, 'destroyed')
|
||||
}, 50)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user