1
1
import { triggerUpdate } from '../client/update'
2
2
import { isUndefined , isFunction } from '../utils/is-type'
3
+ import { find } from '../utils/array'
3
4
import { ensuredPush } from '../utils/ensure'
4
5
import { rootConfigKey } from './constants'
5
6
import { hasMetaInfo } from './meta-helpers'
@@ -18,12 +19,13 @@ export default function createMixin (Vue, options) {
18
19
const rootKey = '$root'
19
20
const $root = this [ rootKey ]
20
21
const $options = this . $options
22
+ const devtoolsEnabled = Vue . config . devtools
21
23
22
24
Object . defineProperty ( this , '_hasMetaInfo' , {
23
25
configurable : true ,
24
26
get ( ) {
25
27
// Show deprecation warning once when devtools enabled
26
- if ( Vue . config . devtools && ! $root [ rootConfigKey ] . deprecationWarningShown ) {
28
+ if ( devtoolsEnabled && ! $root [ rootConfigKey ] . deprecationWarningShown ) {
27
29
warn ( 'VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead' )
28
30
$root [ rootConfigKey ] . deprecationWarningShown = true
29
31
}
@@ -41,6 +43,17 @@ export default function createMixin (Vue, options) {
41
43
if ( ! $root [ rootConfigKey ] ) {
42
44
$root [ rootConfigKey ] = { appId }
43
45
appId ++
46
+
47
+ if ( devtoolsEnabled && $root . $options [ options . keyName ] ) {
48
+ // use nextTick so the children should be added to $root
49
+ this . $nextTick ( ( ) => {
50
+ // find the first child that lists fnOptions
51
+ const child = find ( $root . $children , c => c . $vnode && c . $vnode . fnOptions )
52
+ if ( child && child . $vnode . fnOptions [ options . keyName ] ) {
53
+ warn ( `VueMeta has detected a possible global mixin which adds a ${ options . keyName } property to all Vue components on the page. This could cause severe performance issues. If possible, use $meta().addApp to add meta information instead` )
54
+ }
55
+ } )
56
+ }
44
57
}
45
58
46
59
// to speed up updates we keep track of branches which have a component with vue-meta info defined
@@ -83,14 +96,18 @@ export default function createMixin (Vue, options) {
83
96
$root [ rootConfigKey ] . initialized = this . $isServer
84
97
85
98
if ( ! $root [ rootConfigKey ] . initialized ) {
86
- ensuredPush ( $options , 'beforeMount' , function ( ) {
87
- const $root = this [ rootKey ]
88
- // if this Vue-app was server rendered, set the appId to 'ssr'
89
- // only one SSR app per page is supported
90
- if ( $root . $el && $root . $el . nodeType === 1 && $root . $el . hasAttribute ( 'data-server-rendered' ) ) {
91
- $root [ rootConfigKey ] . appId = options . ssrAppId
92
- }
93
- } )
99
+ if ( ! $root [ rootConfigKey ] . initializedSsr ) {
100
+ $root [ rootConfigKey ] . initializedSsr = true
101
+
102
+ ensuredPush ( $options , 'beforeMount' , function ( ) {
103
+ const $root = this
104
+ // if this Vue-app was server rendered, set the appId to 'ssr'
105
+ // only one SSR app per page is supported
106
+ if ( $root . $el && $root . $el . nodeType === 1 && $root . $el . hasAttribute ( 'data-server-rendered' ) ) {
107
+ $root [ rootConfigKey ] . appId = options . ssrAppId
108
+ }
109
+ } )
110
+ }
94
111
95
112
// we use the mounted hook here as on page load
96
113
ensuredPush ( $options , 'mounted' , function ( ) {
@@ -155,6 +172,7 @@ export default function createMixin (Vue, options) {
155
172
if ( ! this . $parent || ! hasMetaInfo ( this ) ) {
156
173
return
157
174
}
175
+ delete this . _hasMetaInfo
158
176
159
177
this . $nextTick ( ( ) => {
160
178
if ( ! options . waitOnDestroyed || ! this . $el || ! this . $el . offsetParent ) {
0 commit comments