fix(nuxt3): prevent removing and re-adding tags before mount (#3212)

Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
Daniel Roe 2022-02-15 09:43:17 +00:00 committed by GitHub
parent 6a93719a89
commit ef69e746d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -77,5 +77,11 @@ export default (ctx, inject) => {
setNuxtAppInstance(proxiedApp) setNuxtAppInstance(proxiedApp)
if (process.client) {
window.onNuxtReady(() => {
nuxtApp.hooks.callHook('app:mounted', nuxtApp.vueApp)
})
}
inject('_nuxtApp', proxiedApp) inject('_nuxtApp', proxiedApp)
} }

View File

@ -7,6 +7,7 @@ export default defineNuxtPlugin((nuxtApp) => {
const head = createHead() const head = createHead()
nuxtApp.vueApp.use(head) nuxtApp.vueApp.use(head)
nuxtApp.hooks.hookOnce('app:mounted', () => { watchEffect(() => head.updateDOM()) })
nuxtApp._useMeta = (meta: MetaObject) => { nuxtApp._useMeta = (meta: MetaObject) => {
const headObj = ref(meta as any) const headObj = ref(meta as any)
@ -14,16 +15,11 @@ export default defineNuxtPlugin((nuxtApp) => {
if (process.server) { return } if (process.server) { return }
watchEffect(() => {
head.updateDOM()
})
const vm = getCurrentInstance() const vm = getCurrentInstance()
if (!vm) { return } if (!vm) { return }
onBeforeUnmount(() => { onBeforeUnmount(() => {
head.removeHeadObjs(headObj) head.removeHeadObjs(headObj)
head.updateDOM()
}) })
} }