diff --git a/packages/nuxt/src/app/composables/component.ts b/packages/nuxt/src/app/composables/component.ts index 9213550011..faf4a0abcf 100644 --- a/packages/nuxt/src/app/composables/component.ts +++ b/packages/nuxt/src/app/composables/component.ts @@ -5,6 +5,7 @@ import type { NuxtApp } from '../nuxt' import { callWithNuxt, useNuxtApp } from '../nuxt' import { useAsyncData } from './asyncData' import { useRoute } from './router' +import { createError } from './error' export const NuxtComponentIndicator = '__nuxt_component' @@ -14,7 +15,10 @@ async function runLegacyAsyncData (res: Record | Promise '') : fetchKey || route.fullPath - const { data } = await useAsyncData(`options:asyncdata:${key}`, () => callWithNuxt(nuxt, fn, [nuxt])) + const { data, error } = await useAsyncData(`options:asyncdata:${key}`, () => callWithNuxt(nuxt, fn, [nuxt])) + if (error.value) { + throw createError(error.value) + } if (data.value && typeof data.value === 'object') { Object.assign(await res, toRefs(reactive(data.value))) } else if (process.dev) { diff --git a/test/basic.test.ts b/test/basic.test.ts index 14e5a57d8a..0755a888cf 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -353,6 +353,13 @@ describe('pages', () => { await page.waitForLoadState('networkidle') expect(await page.locator('#async-server-component-count').innerHTML()).toContain(('1')) expect(await page.locator('#long-async-component-count').innerHTML()).toContain('1') + await page.close() + }) + + it('/legacy-async-data-fail', async () => { + const response = await fetch('/legacy-async-data-fail').then(r => r.text()) + expect(response).not.toContain('don\'t look at this') + expect(response).toContain('OH NNNNNNOOOOOOOOOOO') }) }) diff --git a/test/fixtures/basic/pages/legacy-async-data-fail.vue b/test/fixtures/basic/pages/legacy-async-data-fail.vue new file mode 100644 index 0000000000..072c4ae000 --- /dev/null +++ b/test/fixtures/basic/pages/legacy-async-data-fail.vue @@ -0,0 +1,13 @@ + + +