Skip to content

Commit

Permalink
fix(Theme): fix theme issue when using Vue Meta without SSR (#8079)
Browse files Browse the repository at this point in the history
* fix: fix theme when using SSR & Vue Meta

* fix tests

* change test name

* fix tests

* remove duplicated output in snapshot
  • Loading branch information
kevinmarrec authored and johnleider committed Jul 30, 2019
1 parent e38a763 commit 681051d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion packages/vuetify/src/services/theme/__tests__/theme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions packages/vuetify/src/services/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 681051d

Please sign in to comment.