diff --git a/packages/bridge/src/runtime/head/plugins/unhead.ts b/packages/bridge/src/runtime/head/plugins/unhead.ts index 87a31203..c68cd103 100644 --- a/packages/bridge/src/runtime/head/plugins/unhead.ts +++ b/packages/bridge/src/runtime/head/plugins/unhead.ts @@ -1,7 +1,12 @@ -import { createHead as createClientHead, createServerHead, Vue2ProvideUnheadPlugin } from '@unhead/vue' +import { + createHead as createClientHead, + createServerHead, + setHeadInjectionHandler, + Vue2ProvideUnheadPlugin +} from '@unhead/vue' import { markRaw } from 'vue' import { renderSSRHead } from '@unhead/ssr' -import { defineNuxtPlugin } from '../../app' +import { defineNuxtPlugin, useNuxtApp } from '../../app' // @ts-ignore import metaConfig from '#build/meta.config.mjs' @@ -9,9 +14,15 @@ export default defineNuxtPlugin((nuxtApp) => { const createHead = process.server ? createServerHead : createClientHead const head = createHead() head.push(markRaw(metaConfig.globalMeta)) - + // TODO the replacement plugin has issues in Nuxt, needs to be fixed upstream nuxtApp.vueApp.use(Vue2ProvideUnheadPlugin, head) - nuxtApp.vueApp.use(head) + nuxtApp.vueApp.config.globalProperties.$head = head + + // allow useHead to be used outside a Vue context but within a Nuxt context + setHeadInjectionHandler( + // need a fresh instance of the nuxt app to avoid parallel requests interfering with each other + () => useNuxtApp().vueApp.config.globalProperties.$head + ) if (process.server) { nuxtApp.ssrContext!.renderMeta = async () => {