mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix(bridge): define mixin outside plugin, to avoid memory leak (#3900)
This commit is contained in:
parent
38e92597f4
commit
7c1a8ae0d9
@ -1,7 +1,7 @@
|
|||||||
import { computed, getCurrentInstance } from 'vue'
|
import { computed, getCurrentInstance } from 'vue'
|
||||||
import * as Components from './components'
|
import * as Components from './components'
|
||||||
import { useMeta } from './composables'
|
import { useMeta } from './composables'
|
||||||
import { defineNuxtPlugin } from '#app'
|
import { defineNuxtPlugin, useNuxtApp } from '#app'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import metaConfig from '#build/meta.config.mjs'
|
import metaConfig from '#build/meta.config.mjs'
|
||||||
|
|
||||||
@ -10,22 +10,25 @@ declare module 'vue' {
|
|||||||
export interface GlobalComponents extends MetaComponents {}
|
export interface GlobalComponents extends MetaComponents {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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'
|
||||||
|
? computed(() => options.head(nuxtApp))
|
||||||
|
: options.head
|
||||||
|
|
||||||
|
useMeta(source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default defineNuxtPlugin((nuxtApp) => {
|
export default defineNuxtPlugin((nuxtApp) => {
|
||||||
useMeta(metaConfig.globalMeta)
|
useMeta(metaConfig.globalMeta)
|
||||||
|
|
||||||
nuxtApp.vueApp.mixin({
|
nuxtApp.vueApp.mixin(metaMixin)
|
||||||
[metaConfig.mixinKey] () {
|
|
||||||
const instance = getCurrentInstance()
|
|
||||||
const options = instance?.type || /* nuxt2 */ instance?.proxy?.$options
|
|
||||||
if (!options || !('head' in options)) { return }
|
|
||||||
|
|
||||||
const source = typeof options.head === 'function'
|
|
||||||
? computed(() => options.head(nuxtApp))
|
|
||||||
: options.head
|
|
||||||
|
|
||||||
useMeta(source)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
for (const name in Components) {
|
for (const name in Components) {
|
||||||
// eslint-disable-next-line import/namespace
|
// eslint-disable-next-line import/namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user