diff --git a/packages/vuetify/src/services/theme/__tests__/__snapshots__/theme.spec.ts.snap b/packages/vuetify/src/services/theme/__tests__/__snapshots__/theme.spec.ts.snap index 0b0e5b7a435..fcf900f6a19 100644 --- a/packages/vuetify/src/services/theme/__tests__/__snapshots__/theme.spec.ts.snap +++ b/packages/vuetify/src/services/theme/__tests__/__snapshots__/theme.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Theme.ts should add fake child element for nuxt ssr support 1`] = ` +exports[`Theme.ts should add fake child element for vue-meta with ssr support 1`] = ` Object { "style": Array [ Object { diff --git a/packages/vuetify/src/services/theme/__tests__/theme.spec.ts b/packages/vuetify/src/services/theme/__tests__/theme.spec.ts index 73723c0e16a..2edfcc4024b 100644 --- a/packages/vuetify/src/services/theme/__tests__/theme.spec.ts +++ b/packages/vuetify/src/services/theme/__tests__/theme.spec.ts @@ -183,10 +183,18 @@ describe('Theme.ts', () => { expect(ssrContext.head).toMatchSnapshot() }) - it('should add fake child element for nuxt ssr support', () => { + it('should add fake child element for vue-meta with ssr support', () => { const theme = new Theme(mock) ;(instance as any).$meta = {} + // $isServer is read only but need to be set for test purpose : https://github.com/vuejs/vue/issues/9232#issuecomment-477914392 + Object.setPrototypeOf( + instance, + new Proxy(Object.getPrototypeOf(instance), { + get: (target, key, receiver) => key === '$isServer' ? true : Reflect.get(target, key, receiver), + }) + ) + expect(instance.$children).toHaveLength(0) theme.init(instance) diff --git a/packages/vuetify/src/services/theme/index.ts b/packages/vuetify/src/services/theme/index.ts index 6de3d1e841d..695dbf20951 100644 --- a/packages/vuetify/src/services/theme/index.ts +++ b/packages/vuetify/src/services/theme/index.ts @@ -109,14 +109,11 @@ export class Theme extends Service { public init (root: Vue, ssrContext?: any): void { if (this.disabled) return - const meta = Boolean((root as any).$meta) // TODO: don't import public types from /src - const ssr = Boolean(ssrContext) - /* istanbul ignore else */ - if (meta) { - this.initNuxt(root) - } else if (ssr) { + if (ssrContext) { this.initSSR(ssrContext) + } else if (root.$isServer && (root as any).$meta) { + this.initVueMeta(root) } this.initTheme() @@ -178,7 +175,7 @@ export class Theme extends Service { document.head.appendChild(this.styleEl) } - private initNuxt (root: Vue) { + private initVueMeta (root: Vue) { const options = this.options || {} root.$children.push(new Vue({ head: {