fix: wrap legacyasyncdata with runWithCOntext

This commit is contained in:
Julien Huang 2024-08-24 17:27:27 +02:00
parent 3161c1545e
commit 2a47785ddd

View File

@ -47,10 +47,11 @@ export const defineNuxtComponent: typeof defineComponent =
_fetchKeyBase: key, _fetchKeyBase: key,
...options, ...options,
setup (props, ctx) { setup (props, ctx) {
const nuxtApp = useNuxtApp()
const res = setup ? Promise.resolve(setup(props, ctx)).then(r => r || {}) : {} const res = setup ? Promise.resolve(setup(props, ctx)).then(r => r || {}) : {}
const promises: Promise<any>[] = [] const promises: Promise<any>[] = []
if (options.asyncData) { if (options.asyncData) {
promises.push(runLegacyAsyncData(res, options.asyncData)) promises.push(nuxtApp.runWithContext(() => runLegacyAsyncData(res, options.asyncData)))
} }
if (options.head) { if (options.head) {