Skip to content

Commit

Permalink
fix: improve ssr detection when 1st metaInfo component isnt root
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed May 16, 2020
1 parent 32fdb20 commit a41b9a7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/shared/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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
}
})
Expand Down

0 comments on commit a41b9a7

Please sign in to comment.