defineComponent,
getCurrentInstance,
h,
+ nextTick,
onErrorCaptured,
onServerPrefetch,
reactive,
)
} catch {}
expect(getCurrentInstance()).toBe(prev)
+ expect(
+ '[Vue warn]: Unhandled error during execution of render function',
+ ).toHaveBeenWarned()
})
// #7733
expect((capturedError as unknown as Error).message).toBe('An error')
})
+ test('async setup throwing error', async () => {
+ let capturedError: string[] = []
+
+ const Child = {
+ async setup() {
+ await nextTick()
+ throw new Error('An error')
+ return { foo: { bar: 1 } }
+ },
+ template: `<span>{{ foo.bar }}</span>`,
+ }
+
+ const app = createApp({
+ components: { Child },
+ setup() {
+ onErrorCaptured(e => {
+ capturedError.push(e.message)
+ return false
+ })
+ },
+ template: `<Suspense><Child /></Suspense>`,
+ })
+
+ try {
+ await render(app)
+ } catch (e: any) {}
+ expect(capturedError.length).toBe(2)
+ expect(capturedError).toStrictEqual([
+ 'An error',
+ "Cannot read properties of undefined (reading 'bar')",
+ ])
+ expect(
+ '[Vue warn]: Property "foo" was accessed during render but is not defined on instance',
+ ).toHaveBeenWarned()
+ })
+
test('computed reactivity during SSR with onServerPrefetch', async () => {
const store = {
// initial state could be hydrated
type Component,
type ComponentInternalInstance,
type DirectiveBinding,
+ ErrorCodes,
Fragment,
type FunctionalComponent,
Static,
type VNode,
type VNodeArrayChildren,
type VNodeProps,
+ handleError,
mergeProps,
ssrUtils,
warn,
instance.data,
instance.ctx,
)
+ } catch (err) {
+ handleError(err, instance, ErrorCodes.RENDER_FUNCTION)
} finally {
setCurrentRenderingInstance(prev)
}