mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
fix(vue): missing unhead context (#3589)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { computed } from 'vue'
|
||||
import { defineNuxtPlugin, useAppConfig, useNuxtApp, useHead } from '#imports'
|
||||
// FIXME: https://github.com/nuxt/module-builder/issues/141#issuecomment-2078248248
|
||||
import type {} from '#app'
|
||||
import type { UseHeadInput } from '@unhead/vue/types'
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const appConfig = useAppConfig()
|
||||
@@ -33,12 +34,11 @@ export default defineNuxtPlugin(() => {
|
||||
})
|
||||
|
||||
// Head
|
||||
const headData: any = {
|
||||
const headData: UseHeadInput = {
|
||||
style: [{
|
||||
innerHTML: () => root.value,
|
||||
tagPriority: -2,
|
||||
id: 'nuxt-ui-colors',
|
||||
type: 'text/css'
|
||||
tagPriority: 'critical',
|
||||
id: 'nuxt-ui-colors'
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -55,7 +55,5 @@ export default defineNuxtPlugin(() => {
|
||||
}]
|
||||
}
|
||||
|
||||
if (!nuxtApp.isVue) {
|
||||
useHead(headData)
|
||||
}
|
||||
useHead(headData)
|
||||
})
|
||||
|
||||
@@ -3,6 +3,11 @@ import type { Plugin } from 'vue'
|
||||
|
||||
export default {
|
||||
install(app) {
|
||||
// check for existing head instance to avoid replacement
|
||||
// bit hacky but we can't use injectHead() here
|
||||
if (app._context.provides.usehead) {
|
||||
return
|
||||
}
|
||||
const head = createHead()
|
||||
app.use(head)
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ export const useState = <T>(key: string, init: () => T): Ref<T> => {
|
||||
export function useNuxtApp() {
|
||||
return {
|
||||
isHydrating: true,
|
||||
isVue: true,
|
||||
payload: { serverRendered: false }
|
||||
}
|
||||
}
|
||||
@@ -69,7 +68,7 @@ export function useNuxtApp() {
|
||||
export function defineNuxtPlugin(plugin: (nuxtApp: NuxtApp) => void) {
|
||||
return {
|
||||
install(app) {
|
||||
plugin({ vueApp: app } as NuxtApp)
|
||||
app.runWithContext(() => plugin({ vueApp: app } as NuxtApp))
|
||||
}
|
||||
} satisfies VuePlugin
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user