mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix(bridge): don't double-install plugins when using compat vueApp.use
(#3898)
This commit is contained in:
parent
c7f4e3c709
commit
773dd59a2c
@ -194,6 +194,10 @@ export default defineNuxtPlugin(nuxtApp => {
|
|||||||
If you want to use the new Nuxt composables (such as `useNuxtApp` or `useRuntimeConfig`) within your plugins, you will need to use the `defineNuxtPlugin` helper for those plugins.
|
If you want to use the new Nuxt composables (such as `useNuxtApp` or `useRuntimeConfig`) within your plugins, you will need to use the `defineNuxtPlugin` helper for those plugins.
|
||||||
::
|
::
|
||||||
|
|
||||||
|
::alert{type=warning}
|
||||||
|
Although a compatibility interface is provided via `nuxtApp.vueApp` you should avoid registering plugins, directives, mixins or components this way without adding your own logic to ensure they are not installed more than once, or this may cause a memory leak.
|
||||||
|
::
|
||||||
|
|
||||||
## New `useMeta` (optional)
|
## New `useMeta` (optional)
|
||||||
|
|
||||||
Nuxt Bridge provides a new Nuxt 3 meta API that can be accessed with a new `useMeta` composable.
|
Nuxt Bridge provides a new Nuxt 3 meta API that can be accessed with a new `useMeta` composable.
|
||||||
|
@ -19,20 +19,29 @@ function proxiedState (state) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const runOnceWith = (obj, fn) => {
|
||||||
|
if (!obj || !['function', 'object'].includes(typeof obj)) {
|
||||||
|
return fn()
|
||||||
|
}
|
||||||
|
if (obj.__nuxt_installed) { return }
|
||||||
|
obj.__nuxt_installed = true
|
||||||
|
return fn()
|
||||||
|
}
|
||||||
|
|
||||||
export default async (ctx, inject) => {
|
export default async (ctx, inject) => {
|
||||||
const nuxtApp = {
|
const nuxtApp = {
|
||||||
vueApp: {
|
vueApp: {
|
||||||
component: Vue.component.bind(Vue),
|
component: (id, definition) => runOnceWith(definition, () => Vue.component(id, definition)),
|
||||||
config: {
|
config: {
|
||||||
globalProperties: {}
|
globalProperties: {}
|
||||||
},
|
},
|
||||||
directive: Vue.directive.bind(Vue),
|
directive: (id, definition) => runOnceWith(definition, () => Vue.directive(id, definition)),
|
||||||
mixin: Vue.mixin.bind(Vue),
|
mixin: mixin => runOnceWith(mixin, () => Vue.mixin(mixin)),
|
||||||
mount: () => { },
|
mount: () => { },
|
||||||
provide: inject,
|
provide: inject,
|
||||||
unmount: () => { },
|
unmount: () => { },
|
||||||
use (vuePlugin) {
|
use (vuePlugin) {
|
||||||
vuePlugin.install(this)
|
runOnceWith(vuePlugin, () => vuePlugin.install(this))
|
||||||
},
|
},
|
||||||
version: Vue.version
|
version: Vue.version
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user