Skip to content

Commit 2dd1697

Browse files
committed
fix: set ssr appId in mounted hook
vm. is not yet set in beforeMount
1 parent 62290c1 commit 2dd1697

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/shared/mixin.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,14 @@ export default function createMixin(Vue, options) {
7575
this.$root._vueMeta.initialized = this.$isServer
7676

7777
if (!this.$root._vueMeta.initialized) {
78-
ensuredPush(this.$options, 'beforeMount', () => {
78+
// we use the mounted hook here as on page load
79+
ensuredPush(this.$options, 'mounted', () => {
7980
// if this Vue-app was server rendered, set the appId to 'ssr'
8081
// only one SSR app per page is supported
8182
if (this.$root.$el && this.$root.$el.hasAttribute('data-server-rendered')) {
8283
this.$root._vueMeta.appId = 'ssr'
8384
}
84-
})
8585

86-
// we use the mounted hook here as on page load
87-
ensuredPush(this.$options, 'mounted', () => {
8886
if (!this.$root._vueMeta.initialized) {
8987
// used in triggerUpdate to check if a change was triggered
9088
// during initialization

test/unit/components.test.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,15 @@ describe('client', () => {
102102

103103
test('doesnt update when ssr attribute is set', () => {
104104
html.setAttribute(defaultOptions.ssrAttribute, 'true')
105-
const wrapper = mount(HelloWorld, { localVue: Vue })
105+
const wrapper = mount(HelloWorld, {
106+
localVue: Vue,
107+
attrs: {
108+
'data-server-rendered': true
109+
}
110+
})
106111

107112
const { tags } = wrapper.vm.$meta().refresh()
108-
// TODO: fix this test, not sure how to create a wrapper with a attri
109-
// bute data-server-rendered="true"
110-
expect(tags).not.toBe(false)
113+
expect(tags).toBe(false)
111114
})
112115

113116
test('changed function is called', async () => {
@@ -229,7 +232,12 @@ describe('client', () => {
229232
}
230233
})
231234

232-
const wrapper = mount(component, { localVue: Vue })
235+
const wrapper = mount(component, {
236+
localVue: Vue,
237+
attrs: {
238+
'data-server-rendered': true
239+
}
240+
})
233241
expect(html.getAttribute('theme')).not.toBe('dark')
234242

235243
await vmTick(wrapper.vm)

0 commit comments

Comments
 (0)