-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(nuxt3, bridge): add vue:setup
hook
#2408
Conversation
βοΈ Deploy Preview for nuxt3-docs ready! π¨ Explore the source changes: 3f03934 π Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/61c1e6f02603a600089110d1 π Browse the preview: https://deploy-preview-2408--nuxt3-docs.netlify.app |
I love it! |
|
||
nuxtApp.nuxt2Context.app.setup = function (...args) { | ||
const result = _originalSetup instanceof Function ? _originalSetup(...args) : {} | ||
nuxtApp.callHook('vue:setup') |
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.
Shouldn't we avoid on setup? (if capi's setup does not supports, at least need to handle promise's catch or warn user about async if promise returned)
|
||
export default { | ||
setup () { | ||
useNuxtApp().callHook('vue:setup') |
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.
We should await on this call (or chain promise)
useNuxtApp().callHook('vue:setup') | |
return useNuxtApp().callHook('vue:setup') |
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.
If we await this call we will need another root component with suspense above this one. I think it's reasonable to require vue:setup
hook to have only syncronous callbacks (but happy to implement that or another solution if we need this to be async).
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.
Your reasoning makes sense but in this case, we need to handle two cases:
- In server-side, strictly disallow returning promise as it can potentially resolve after rendering lifecycle
- Handle rejected promises
Maybe as a simple solution simply detect and warn about async usage?
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.
Sounds good to me π Will implement.
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.
pushed an implementation but will open a PR to add support for sync calling of hooks in hookable (unjs/hookable#34)
Super keen for this π€© |
π Linked issue
resolves nuxt/nuxt#12828, resolves nuxt/bridge#222
β Type of change
π Description
This PR adds a
vue:setup
hook that is called within the rootsetup()
function of the app. This also provides a full replacement foronGlobalSetup
in the legacy composition API module.Note: it will not be awaited because we are 'outside' of the root
<Suspense>
.π Checklist