mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 00:40:35 +03:00
fix: improve ssr detection when 1st metaInfo component isnt root
This commit is contained in:
+9
-2
@@ -11,6 +11,7 @@ let appId = 1
|
|||||||
export default function createMixin (Vue, options) {
|
export default function createMixin (Vue, options) {
|
||||||
// for which Vue lifecycle hooks should the metaInfo be refreshed
|
// for which Vue lifecycle hooks should the metaInfo be refreshed
|
||||||
const updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount']
|
const updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount']
|
||||||
|
let wasServerRendered = false
|
||||||
|
|
||||||
// watch for client side component updates
|
// watch for client side component updates
|
||||||
return {
|
return {
|
||||||
@@ -20,6 +21,12 @@ export default function createMixin (Vue, options) {
|
|||||||
const $options = this.$options
|
const $options = this.$options
|
||||||
const devtoolsEnabled = Vue.config.devtools
|
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', {
|
Object.defineProperty(this, '_hasMetaInfo', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
get () {
|
get () {
|
||||||
@@ -99,10 +106,10 @@ export default function createMixin (Vue, options) {
|
|||||||
$root[rootConfigKey].initializedSsr = true
|
$root[rootConfigKey].initializedSsr = true
|
||||||
|
|
||||||
this.$on('hook:beforeMount', function () {
|
this.$on('hook:beforeMount', function () {
|
||||||
const $root = this
|
const $root = this[rootKey]
|
||||||
// if this Vue-app was server rendered, set the appId to 'ssr'
|
// if this Vue-app was server rendered, set the appId to 'ssr'
|
||||||
// only one SSR app per page is supported
|
// 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
|
$root[rootConfigKey].appId = options.ssrAppId
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user