diff --git a/packages/nuxt/src/app/composables/asyncData.ts b/packages/nuxt/src/app/composables/asyncData.ts index d4ac4e49ec..8a7d7948cd 100644 --- a/packages/nuxt/src/app/composables/asyncData.ts +++ b/packages/nuxt/src/app/composables/asyncData.ts @@ -143,7 +143,7 @@ export function useAsyncData< const promise = new Promise( (resolve, reject) => { try { - resolve(handler(nuxt)) + resolve(nuxt.runWithContext(() => handler(nuxt))) } catch (err) { reject(err) } diff --git a/packages/schema/src/config/build.ts b/packages/schema/src/config/build.ts index 9c72526734..7468cf47f5 100644 --- a/packages/schema/src/config/build.ts +++ b/packages/schema/src/config/build.ts @@ -193,7 +193,7 @@ export default defineUntypedSchema({ * @type {import('unctx').TransformerOptions} */ asyncTransforms: { - asyncFunctions: ['defineNuxtPlugin', 'defineNuxtRouteMiddleware'], + asyncFunctions: ['defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'runWithContext', 'useAsyncData'], objectDefinitions: { defineNuxtComponent: ['asyncData', 'setup'], defineNuxtPlugin: ['setup'],