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 fcf900f6a19..e6518afdafa 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 vue-meta with ssr support 1`] = ` +exports[`Theme.ts should add fake child element for vue-meta 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 2edfcc4024b..6c29a12899a 100644 --- a/packages/vuetify/src/services/theme/__tests__/theme.spec.ts +++ b/packages/vuetify/src/services/theme/__tests__/theme.spec.ts @@ -183,18 +183,10 @@ describe('Theme.ts', () => { expect(ssrContext.head).toMatchSnapshot() }) - it('should add fake child element for vue-meta with ssr support', () => { + it('should add fake child element for vue-meta 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) @@ -205,7 +197,7 @@ describe('Theme.ts', () => { const head = options.head expect(head).toBeTruthy() - expect(head).toMatchSnapshot() + expect(head()).toMatchSnapshot() }) it('should react to theme changes', async () => { diff --git a/packages/vuetify/src/services/theme/index.ts b/packages/vuetify/src/services/theme/index.ts index 695dbf20951..bd7522641fd 100644 --- a/packages/vuetify/src/services/theme/index.ts +++ b/packages/vuetify/src/services/theme/index.ts @@ -110,10 +110,10 @@ export class Theme extends Service { if (this.disabled) return /* istanbul ignore else */ - if (ssrContext) { - this.initSSR(ssrContext) - } else if (root.$isServer && (root as any).$meta) { + if ((root as any).$meta) { this.initVueMeta(root) + } else if (ssrContext) { + this.initSSR(ssrContext) } this.initTheme() @@ -178,15 +178,17 @@ export class Theme extends Service { private initVueMeta (root: Vue) { const options = this.options || {} root.$children.push(new Vue({ - head: { - style: [ - { - cssText: this.generatedStyles, - type: 'text/css', - id: 'vuetify-theme-stylesheet', - nonce: options.cspNonce, - }, - ], + head: () => { + return { + style: [ + { + cssText: this.generatedStyles, + type: 'text/css', + id: 'vuetify-theme-stylesheet', + nonce: options.cspNonce, + }, + ], + } }, } as any)) }