mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 00:20:34 +03:00
fix: set ssr appId in mounted hook
vm. is not yet set in beforeMount
This commit is contained in:
+2
-4
@@ -75,16 +75,14 @@ export default function createMixin(Vue, options) {
|
|||||||
this.$root._vueMeta.initialized = this.$isServer
|
this.$root._vueMeta.initialized = this.$isServer
|
||||||
|
|
||||||
if (!this.$root._vueMeta.initialized) {
|
if (!this.$root._vueMeta.initialized) {
|
||||||
ensuredPush(this.$options, 'beforeMount', () => {
|
// we use the mounted hook here as on page load
|
||||||
|
ensuredPush(this.$options, 'mounted', () => {
|
||||||
// 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 (this.$root.$el && this.$root.$el.hasAttribute('data-server-rendered')) {
|
if (this.$root.$el && this.$root.$el.hasAttribute('data-server-rendered')) {
|
||||||
this.$root._vueMeta.appId = 'ssr'
|
this.$root._vueMeta.appId = 'ssr'
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
// we use the mounted hook here as on page load
|
|
||||||
ensuredPush(this.$options, 'mounted', () => {
|
|
||||||
if (!this.$root._vueMeta.initialized) {
|
if (!this.$root._vueMeta.initialized) {
|
||||||
// used in triggerUpdate to check if a change was triggered
|
// used in triggerUpdate to check if a change was triggered
|
||||||
// during initialization
|
// during initialization
|
||||||
|
|||||||
@@ -102,12 +102,15 @@ describe('client', () => {
|
|||||||
|
|
||||||
test('doesnt update when ssr attribute is set', () => {
|
test('doesnt update when ssr attribute is set', () => {
|
||||||
html.setAttribute(defaultOptions.ssrAttribute, 'true')
|
html.setAttribute(defaultOptions.ssrAttribute, 'true')
|
||||||
const wrapper = mount(HelloWorld, { localVue: Vue })
|
const wrapper = mount(HelloWorld, {
|
||||||
|
localVue: Vue,
|
||||||
|
attrs: {
|
||||||
|
'data-server-rendered': true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const { tags } = wrapper.vm.$meta().refresh()
|
const { tags } = wrapper.vm.$meta().refresh()
|
||||||
// TODO: fix this test, not sure how to create a wrapper with a attri
|
expect(tags).toBe(false)
|
||||||
// bute data-server-rendered="true"
|
|
||||||
expect(tags).not.toBe(false)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('changed function is called', async () => {
|
test('changed function is called', async () => {
|
||||||
@@ -229,7 +232,12 @@ describe('client', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const wrapper = mount(component, { localVue: Vue })
|
const wrapper = mount(component, {
|
||||||
|
localVue: Vue,
|
||||||
|
attrs: {
|
||||||
|
'data-server-rendered': true
|
||||||
|
}
|
||||||
|
})
|
||||||
expect(html.getAttribute('theme')).not.toBe('dark')
|
expect(html.getAttribute('theme')).not.toBe('dark')
|
||||||
|
|
||||||
await vmTick(wrapper.vm)
|
await vmTick(wrapper.vm)
|
||||||
|
|||||||
Reference in New Issue
Block a user