-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(bridge): add useNuxtApp
and defineNuxtPlugin
composables
#576
Conversation
Deploying with Β Β Cloudflare Pages
|
packages/bridge/src/runtime/app.mjs
Outdated
const vm = getCurrentInstance() | ||
|
||
if (!vm) { | ||
throw new Error('nuxt instance unavailable') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check nuxt 3 implementation: https://github.com/nuxt/framework/blob/main/packages/nuxt3/src/app/nuxt.ts#L181
We should be able to use nuxt app instance outside of vue lifecycle in the client-side (replacing global $nuxt usage) and during the execution of nuxt plugins (making composables for plugins)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on its way!
} | ||
|
||
ctx.app.created.push(function () { | ||
nuxt.app = this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inconsistent with n3 and finally app
instances are not the same. Maybe keeping ctx.app
and this
(created app) as different vue2 only names in the nuxt
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: We would need to expose NuxtAppCompat
interface ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. So something like:
{
legacyApp, // => ctx.app (app options)
legacyThis, // => this
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call first legacyNuxt (it is nuxt interface right?) and legacyApp (vue2 app instance?)
useNuxtApp
composableuseNuxtApp
and defineNuxtPlugin
composables
π Linked issue
nuxt/bridge#105
β Type of change
π Description
This adds a shim for
useNuxtApp
intended to be compatible in API:framework/packages/nuxt3/src/app/nuxt.ts
Lines 67 to 79 in a9c4bfa
I have noted a question below about
nuxt.state
as this is currently unused in nuxt3.I can follow-up with a second PR to add
defineNuxtPlugin
which will work quite closely with this composable, or can implement it here too.Finally, perhaps we can update docs after nuxt/bridge#102 is complete. (Or I can document this individually if preferred.)
π Checklist