Skip to content

Commit

Permalink
fix(theme): fix vue-meta theme on page navigation (#8234)
Browse files Browse the repository at this point in the history
fixes #7879
  • Loading branch information
kevinmarrec authored and johnleider committed Aug 1, 2019
1 parent 4288072 commit 9324ec7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 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 vue-meta with ssr support 1`] = `
exports[`Theme.ts should add fake child element for vue-meta support 1`] = `
Object {
"style": Array [
Object {
Expand Down
12 changes: 2 additions & 10 deletions packages/vuetify/src/services/theme/__tests__/theme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 () => {
Expand Down
26 changes: 14 additions & 12 deletions packages/vuetify/src/services/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 9324ec7

Please sign in to comment.