Skip to content

Commit f2e8eb5

Browse files
pimlieTheAlexLichter
authored andcommitted
feat: track branches which contain metaInfo components
1 parent fa90902 commit f2e8eb5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/shared/inMetaInfoBranch.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { isUndefined } from './typeof'
2+
3+
// a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
4+
export default function inMetaInfoBranch(vm = this) {
5+
return vm && !isUndefined(vm._vueMeta)
6+
}

src/shared/mixin.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import triggerUpdate from '../client/triggerUpdate'
2+
import hasMetaInfo from './hasMetaInfo'
23
import { isUndefined, isFunction } from './typeof'
34
import { ensuredPush } from './ensure'
45

@@ -16,7 +17,7 @@ export default function createMixin(Vue, options) {
1617
console.warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please import hasMetaInfo and use hasMetaInfo(vm) instead') // eslint-disable-line no-console
1718
this.$root._vueMeta.hasMetaInfoDeprecationWarningShown = true
1819
}
19-
return !!this._vueMeta
20+
return hasMetaInfo(this)
2021
}
2122
})
2223

@@ -28,8 +29,18 @@ export default function createMixin(Vue, options) {
2829
this.$root._vueMeta = {}
2930
}
3031

32+
// to speed up updates we keep track of branches which have a component with vue-meta info defined
33+
// if _vueMeta = true it has info, if _vueMeta = false a child has info
3134
if (!this._vueMeta) {
3235
this._vueMeta = true
36+
37+
let p = this.$parent
38+
while (p && p !== this.$root) {
39+
if (isUndefined(p._vueMeta)) {
40+
p._vueMeta = false
41+
}
42+
p = p.$parent
43+
}
3344
}
3445

3546
// coerce function-style metaInfo to a computed prop so we can observe
@@ -55,7 +66,7 @@ export default function createMixin(Vue, options) {
5566
// force an initial refresh on page load and prevent other lifecycleHooks
5667
// to triggerUpdate until this initial refresh is finished
5768
// this is to make sure that when a page is opened in an inactive tab which
58-
// has throttled rAF/timers we still immeditately set the page title
69+
// has throttled rAF/timers we still immediately set the page title
5970
if (isUndefined(this.$root._vueMeta.initialized)) {
6071
this.$root._vueMeta.initialized = this.$isServer
6172

0 commit comments

Comments
 (0)