Using callWithNuxt in asyncData and fetch (Options API) #1459
Unanswered
Piscinelove
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
We are in the final stages of migrating our projects to Vue 3. And yes… still no full Nuxt 3 for us, the technical debt is huge! 😅
This has been a long and complex migration since all our projects (around a hundred) rely heavily on our internal modules. We have been using Nuxt Bridge for several months and have migrated a large part of our logic to composables.
However, we are currently facing an issue: we want to move the logic from our asyncData and fetch hooks into these new composables, but many of them rely heavily on
useNuxtApp()
.We noticed that Nuxt Bridge handles this properly for plugins and middleware. After reviewing the code, we considered using callWithNuxt to wrap our logic inside these hooks, like this:
We ran some quick tests, and it seems to work fine. However, we are unsure about the implications and potential issues that this approach might cause.
This would only be a temporary solution to help us migrate our logic progressively. Our plan is to first migrate all non-blocking hooks to
useLazyAsyncData
anduseLazyFetch
. The remaining hooks that block rendering will only be migrated in the final step once we are fully on Vue 3, at which point we will transition touseAsyncData
anduseFetch
.Our main question is:
Is it recommended to use
callWithNuxt
this way insideasyncData
andfetch
to migrate logic into composables that depend onuseNuxtApp
? Are there any pitfalls or risks we should be aware of?Thanks in advance for your feedback and advice! 😊
Beta Was this translation helpful? Give feedback.
All reactions