From a41b9a73c0b90cf39d9c93fa66fe3e7d59494f77 Mon Sep 17 00:00:00 2001 From: pimlie Date: Sat, 16 May 2020 18:47:45 +0200 Subject: [PATCH] fix: improve ssr detection when 1st metaInfo component isnt root --- src/shared/mixin.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/shared/mixin.js b/src/shared/mixin.js index 9d94962..53d282c 100644 --- a/src/shared/mixin.js +++ b/src/shared/mixin.js @@ -11,6 +11,7 @@ let appId = 1 export default function createMixin (Vue, options) { // for which Vue lifecycle hooks should the metaInfo be refreshed const updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount'] + let wasServerRendered = false // watch for client side component updates return { @@ -20,6 +21,12 @@ export default function createMixin (Vue, options) { const $options = this.$options const devtoolsEnabled = Vue.config.devtools + if (this === $root) { + this.$on('hook:beforeMount', function () { + wasServerRendered = this.$el && this.$el.nodeType === 1 && this.$el.hasAttribute('data-server-rendered') + }) + } + Object.defineProperty(this, '_hasMetaInfo', { configurable: true, get () { @@ -99,10 +106,10 @@ export default function createMixin (Vue, options) { $root[rootConfigKey].initializedSsr = true this.$on('hook:beforeMount', function () { - const $root = this + const $root = this[rootKey] // if this Vue-app was server rendered, set the appId to 'ssr' // only one SSR app per page is supported - if ($root.$el && $root.$el.nodeType === 1 && $root.$el.hasAttribute('data-server-rendered')) { + if (wasServerRendered) { $root[rootConfigKey].appId = options.ssrAppId } })