fix(bridge): define mixin outside plugin, to avoid memory leak (#3900)

This commit is contained in:
Daniel Roe 2022-03-25 12:51:07 +00:00 committed by GitHub
parent 38e92597f4
commit 7c1a8ae0d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
import { computed, getCurrentInstance } from 'vue'
import * as Components from './components'
import { useMeta } from './composables'
import { defineNuxtPlugin } from '#app'
import { defineNuxtPlugin, useNuxtApp } from '#app'
// @ts-ignore
import metaConfig from '#build/meta.config.mjs'
@ -10,13 +10,11 @@ declare module 'vue' {
export interface GlobalComponents extends MetaComponents {}
}
export default defineNuxtPlugin((nuxtApp) => {
useMeta(metaConfig.globalMeta)
nuxtApp.vueApp.mixin({
const metaMixin = {
[metaConfig.mixinKey] () {
const instance = getCurrentInstance()
const options = instance?.type || /* nuxt2 */ instance?.proxy?.$options
const nuxtApp = useNuxtApp()
if (!options || !('head' in options)) { return }
const source = typeof options.head === 'function'
@ -25,7 +23,12 @@ export default defineNuxtPlugin((nuxtApp) => {
useMeta(source)
}
})
}
export default defineNuxtPlugin((nuxtApp) => {
useMeta(metaConfig.globalMeta)
nuxtApp.vueApp.mixin(metaMixin)
for (const name in Components) {
// eslint-disable-next-line import/namespace