fix(nuxt): mark config head as non-reactive (#4666)

This commit is contained in:
Daniel Roe 2022-04-29 20:12:54 +02:00 committed by GitHub
parent 773c565fef
commit 2a3fbb4c24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import { resolve } from 'pathe' import { resolve } from 'pathe'
import { addPlugin, addTemplate, defineNuxtModule, isNuxt3 } from '@nuxt/kit' import { addPlugin, addTemplate, defineNuxtModule } from '@nuxt/kit'
import defu from 'defu' import defu from 'defu'
import { distDir } from '../dirs' import { distDir } from '../dirs'
import type { MetaObject } from './runtime' import type { MetaObject } from './runtime'
@ -31,7 +31,7 @@ export default defineNuxtModule({
// Add global meta configuration // Add global meta configuration
addTemplate({ addTemplate({
filename: 'meta.config.mjs', filename: 'meta.config.mjs',
getContents: () => 'export default ' + JSON.stringify({ globalMeta, mixinKey: isNuxt3() ? 'created' : 'setup' }) getContents: () => 'export default ' + JSON.stringify({ globalMeta })
}) })
// Add generic plugin // Add generic plugin

View File

@ -1,4 +1,4 @@
import { computed, getCurrentInstance } from 'vue' import { computed, getCurrentInstance, markRaw } from 'vue'
import * as Components from './components' import * as Components from './components'
import { useHead } from './composables' import { useHead } from './composables'
import { defineNuxtPlugin, useNuxtApp } from '#app' import { defineNuxtPlugin, useNuxtApp } from '#app'
@ -11,11 +11,11 @@ declare module 'vue' {
} }
const metaMixin = { const metaMixin = {
[metaConfig.mixinKey] () { created () {
const instance = getCurrentInstance() const instance = getCurrentInstance()
if (!instance) { return } if (!instance) { return }
const options = instance.type || /* nuxt2 */ instance.proxy?.$options const options = instance.type
if (!options || !('head' in options)) { return } if (!options || !('head' in options)) { return }
const nuxtApp = useNuxtApp() const nuxtApp = useNuxtApp()
@ -28,7 +28,7 @@ const metaMixin = {
} }
export default defineNuxtPlugin((nuxtApp) => { export default defineNuxtPlugin((nuxtApp) => {
useHead(metaConfig.globalMeta) useHead(markRaw(metaConfig.globalMeta))
nuxtApp.vueApp.mixin(metaMixin) nuxtApp.vueApp.mixin(metaMixin)