diff --git a/packages/bridge/src/runtime/app.ts b/packages/bridge/src/runtime/app.ts index 007c1ba63f..525c514855 100644 --- a/packages/bridge/src/runtime/app.ts +++ b/packages/bridge/src/runtime/app.ts @@ -58,10 +58,12 @@ export const setNuxtAppInstance = (nuxt: NuxtAppCompat | null) => { currentNuxtAppInstance = nuxt } -export const defineNuxtPlugin = plugin => (ctx: Context) => { - setNuxtAppInstance(ctx.$_nuxtApp) - plugin(ctx.$_nuxtApp) - setNuxtAppInstance(null) +export function defineNuxtPlugin (plugin: (nuxtApp: NuxtAppCompat) => void): (ctx: Context) => void { + return (ctx) => { + setNuxtAppInstance(ctx.$_nuxtApp) + plugin(ctx.$_nuxtApp) + setNuxtAppInstance(null) + } } export const useNuxtApp = () => { diff --git a/packages/bridge/src/runtime/capi.legacy.plugin.mjs b/packages/bridge/src/runtime/capi.legacy.plugin.mjs index cb2a5a0a01..411e3bbb0f 100644 --- a/packages/bridge/src/runtime/capi.legacy.plugin.mjs +++ b/packages/bridge/src/runtime/capi.legacy.plugin.mjs @@ -1,13 +1,13 @@ import { defineNuxtPlugin } from '#app' -export default defineNuxtPlugin((nuxt) => { - nuxt._setupFns = [] +export default defineNuxtPlugin((nuxtApp) => { + nuxtApp._setupFns = [] - const _originalSetup = nuxt.nuxt2Context.app.setup + const _originalSetup = nuxtApp.nuxt2Context.app.setup - nuxt.nuxt2Context.app.setup = function (...args) { + nuxtApp.nuxt2Context.app.setup = function (...args) { const result = _originalSetup instanceof Function ? _originalSetup(...args) : {} - for (const fn of nuxt._setupFns) { + for (const fn of nuxtApp._setupFns) { Object.assign(result, fn.call(this, ...args)) } return result diff --git a/packages/bridge/src/runtime/nitro-bridge.server.mjs b/packages/bridge/src/runtime/nitro-bridge.server.mjs index 53de642511..b961c87204 100644 --- a/packages/bridge/src/runtime/nitro-bridge.server.mjs +++ b/packages/bridge/src/runtime/nitro-bridge.server.mjs @@ -26,12 +26,12 @@ const vueMetaRenderer = (nuxt) => { } } -export default defineNuxtPlugin((nuxt) => { +export default defineNuxtPlugin((nuxtApp) => { const metaRenderers = [vueMetaRenderer] - nuxt.callHook('meta:register', metaRenderers) + nuxtApp.callHook('meta:register', metaRenderers) - nuxt.ssrContext.renderMeta = async () => { + nuxtApp.ssrContext.renderMeta = async () => { const metadata = { htmlAttrs: '', headAttrs: '', @@ -41,7 +41,7 @@ export default defineNuxtPlugin((nuxt) => { bodyScripts: '' } for await (const renderer of metaRenderers) { - const result = await renderer(nuxt) + const result = await renderer(nuxtApp) for (const key in result) { metadata[key] += result[key] } diff --git a/packages/nuxt3/src/meta/runtime/lib/vue-meta.plugin.ts b/packages/nuxt3/src/meta/runtime/lib/vue-meta.plugin.ts index 03b8bc66f3..86a7a83815 100644 --- a/packages/nuxt3/src/meta/runtime/lib/vue-meta.plugin.ts +++ b/packages/nuxt3/src/meta/runtime/lib/vue-meta.plugin.ts @@ -3,12 +3,12 @@ import { createMetaManager } from 'vue-meta' import type { MetaObject } from '../types' import { defineNuxtPlugin } from '#app' -export default defineNuxtPlugin((nuxt) => { +export default defineNuxtPlugin((nuxtApp) => { const manager = createMetaManager(process.server) - nuxt.vueApp.use(manager) + nuxtApp.vueApp.use(manager) - nuxt._useMeta = (meta: MetaObject) => manager.addMeta(meta) + nuxtApp._useMeta = (meta: MetaObject) => manager.addMeta(meta) if (process.client) { const teleportTarget = document.createElement('div') @@ -19,19 +19,19 @@ export default defineNuxtPlugin((nuxt) => { } if (process.server) { - nuxt.ssrContext.renderMeta = async () => { + nuxtApp.ssrContext.renderMeta = async () => { const { renderMetaToString } = await import('vue-meta/ssr') - nuxt.ssrContext.teleports = nuxt.ssrContext.teleports || {} + nuxtApp.ssrContext.teleports = nuxtApp.ssrContext.teleports || {} - await renderMetaToString(nuxt.app, nuxt.ssrContext) + await renderMetaToString(nuxtApp.app, nuxtApp.ssrContext) return { - htmlAttrs: nuxt.ssrContext.teleports.htmlAttrs || '', - headAttrs: nuxt.ssrContext.teleports.headAttrs || '', - bodyAttrs: nuxt.ssrContext.teleports.bodyAttrs || '', - headTags: nuxt.ssrContext.teleports.head || '', - bodyPrepend: nuxt.ssrContext.teleports['body-prepend'] || '', - bodyScripts: nuxt.ssrContext.teleports.body || '' + htmlAttrs: nuxtApp.ssrContext.teleports.htmlAttrs || '', + headAttrs: nuxtApp.ssrContext.teleports.headAttrs || '', + bodyAttrs: nuxtApp.ssrContext.teleports.bodyAttrs || '', + headTags: nuxtApp.ssrContext.teleports.head || '', + bodyPrepend: nuxtApp.ssrContext.teleports['body-prepend'] || '', + bodyScripts: nuxtApp.ssrContext.teleports.body || '' } } } diff --git a/packages/nuxt3/src/meta/runtime/lib/vueuse-head.plugin.ts b/packages/nuxt3/src/meta/runtime/lib/vueuse-head.plugin.ts index 7698a3b1b6..c073a7cc59 100644 --- a/packages/nuxt3/src/meta/runtime/lib/vueuse-head.plugin.ts +++ b/packages/nuxt3/src/meta/runtime/lib/vueuse-head.plugin.ts @@ -3,12 +3,12 @@ import { ref, watchEffect, onBeforeUnmount, getCurrentInstance } from 'vue' import type { MetaObject } from '..' import { defineNuxtPlugin } from '#app' -export default defineNuxtPlugin((nuxt) => { +export default defineNuxtPlugin((nuxtApp) => { const head = createHead() - nuxt.vueApp.use(head) + nuxtApp.vueApp.use(head) - nuxt._useMeta = (meta: MetaObject) => { + nuxtApp._useMeta = (meta: MetaObject) => { const headObj = ref(meta as any) head.addHeadObjs(headObj) @@ -28,6 +28,6 @@ export default defineNuxtPlugin((nuxt) => { } if (process.server) { - nuxt.ssrContext.renderMeta = () => renderHeadToString(head) + nuxtApp.ssrContext.renderMeta = () => renderHeadToString(head) } }) diff --git a/test/fixtures/bridge/plugins/setup.js b/test/fixtures/bridge/plugins/setup.js index 25e13f2326..e9370590fe 100644 --- a/test/fixtures/bridge/plugins/setup.js +++ b/test/fixtures/bridge/plugins/setup.js @@ -2,10 +2,10 @@ import { onGlobalSetup, ref } from '@nuxtjs/composition-api' import { defineNuxtPlugin } from '#app' -export default defineNuxtPlugin((nuxt) => { +export default defineNuxtPlugin((nuxtApp) => { const globalsetup = ref('🚧') onGlobalSetup(() => { globalsetup.value = '✅' }) - nuxt.provide('globalsetup', globalsetup) + nuxtApp.provide('globalsetup', globalsetup) })