1
1
import triggerUpdate from '../client/triggerUpdate'
2
- import { isUndefined , isFunction } from '../shared /typeof'
3
- import { ensuredPush } from '../shared /ensure'
2
+ import { isUndefined , isFunction } from './typeof'
3
+ import { ensuredPush } from './ensure'
4
4
5
5
export default function createMixin ( options ) {
6
6
// for which Vue lifecycle hooks should the metaInfo be refreshed
@@ -35,10 +35,6 @@ export default function createMixin(options) {
35
35
}
36
36
}
37
37
38
- updateOnLifecycleHook . forEach ( ( lifecycleHook ) => {
39
- ensuredPush ( this . $options , lifecycleHook , ( ) => triggerUpdate ( this , lifecycleHook ) )
40
- } )
41
-
42
38
// force an initial refresh on page load and prevent other lifecycleHooks
43
39
// to triggerUpdate until this initial refresh is finished
44
40
// this is to make sure that when a page is opened in an inactive tab which
@@ -49,6 +45,7 @@ export default function createMixin(options) {
49
45
if ( ! this . $root . _vueMetaInitialized ) {
50
46
ensuredPush ( this . $options , 'mounted' , ( ) => {
51
47
if ( ! this . $root . _vueMetaInitialized ) {
48
+ // refresh meta in nextTick so all child components have loaded
52
49
this . $nextTick ( function ( ) {
53
50
this . $root . $meta ( ) . refresh ( )
54
51
this . $root . _vueMetaInitialized = true
@@ -60,6 +57,11 @@ export default function createMixin(options) {
60
57
61
58
// do not trigger refresh on the server side
62
59
if ( ! this . $isServer ) {
60
+ // no need to add this hooks on server side, there we only need the mounted hook above
61
+ updateOnLifecycleHook . forEach ( ( lifecycleHook ) => {
62
+ ensuredPush ( this . $options , lifecycleHook , ( ) => triggerUpdate ( this , lifecycleHook ) )
63
+ } )
64
+
63
65
// re-render meta data when returning from a child component to parent
64
66
ensuredPush ( this . $options , 'destroyed' , ( ) => {
65
67
// Wait that element is hidden before refreshing meta tags (to support animations)
@@ -80,54 +82,5 @@ export default function createMixin(options) {
80
82
}
81
83
}
82
84
}
83
- /* Not yet removed
84
- created() {
85
- // if computed $metaInfo exists, watch it for updates & trigger a refresh
86
- // when it changes (i.e. automatically handle async actions that affect metaInfo)
87
- // credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux)
88
- if (!this.$isServer && this.$metaInfo) {
89
- this.$watch('$metaInfo', () => triggerUpdate(this))
90
- }
91
-
92
- },
93
- activated() {
94
- if (this._hasMetaInfo) {
95
- triggerUpdate(this)
96
- }
97
- },
98
- deactivated() {
99
- if (this._hasMetaInfo) {
100
- triggerUpdate(this)
101
- }
102
- },
103
- beforeMount() {
104
- if (this._hasMetaInfo) {
105
- triggerUpdate(this)
106
- }
107
- },
108
- destroyed() {
109
- // do not trigger refresh on the server side
110
- if (this.$isServer) {
111
- return
112
- }
113
-
114
- // re-render meta data when returning from a child component to parent
115
- if (this._hasMetaInfo) {
116
- // Wait that element is hidden before refreshing meta tags (to support animations)
117
- const interval = setInterval(() => {
118
- if (this.$el && this.$el.offsetParent !== null) {
119
- return
120
- }
121
-
122
- clearInterval(interval)
123
-
124
- if (!this.$parent) {
125
- return
126
- }
127
-
128
- triggerUpdate(this)
129
- }, 50)
130
- }
131
- }/**/
132
85
}
133
86
}
0 commit comments