Skip to content

Commit a41b9a7

Browse files
committed
fix: improve ssr detection when 1st metaInfo component isnt root
1 parent 32fdb20 commit a41b9a7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/shared/mixin.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let appId = 1
1111
export default function createMixin (Vue, options) {
1212
// for which Vue lifecycle hooks should the metaInfo be refreshed
1313
const updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount']
14+
let wasServerRendered = false
1415

1516
// watch for client side component updates
1617
return {
@@ -20,6 +21,12 @@ export default function createMixin (Vue, options) {
2021
const $options = this.$options
2122
const devtoolsEnabled = Vue.config.devtools
2223

24+
if (this === $root) {
25+
this.$on('hook:beforeMount', function () {
26+
wasServerRendered = this.$el && this.$el.nodeType === 1 && this.$el.hasAttribute('data-server-rendered')
27+
})
28+
}
29+
2330
Object.defineProperty(this, '_hasMetaInfo', {
2431
configurable: true,
2532
get () {
@@ -99,10 +106,10 @@ export default function createMixin (Vue, options) {
99106
$root[rootConfigKey].initializedSsr = true
100107

101108
this.$on('hook:beforeMount', function () {
102-
const $root = this
109+
const $root = this[rootKey]
103110
// if this Vue-app was server rendered, set the appId to 'ssr'
104111
// only one SSR app per page is supported
105-
if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) {
112+
if (wasServerRendered) {
106113
$root[rootConfigKey].appId = options.ssrAppId
107114
}
108115
})

0 commit comments

Comments
 (0)