diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 3ed42ed0b55..a4051e4a1b5 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -35,7 +35,12 @@ import { initSlots, } from './componentSlots' import { warn } from './warning' -import { ErrorCodes, callWithErrorHandling, handleError } from './errorHandling' +import { + ErrorCodes, + callWithAsyncErrorHandling, + callWithErrorHandling, + handleError, +} from './errorHandling' import { type AppConfig, type AppContext, @@ -67,6 +72,7 @@ import { extend, getGlobalThis, isArray, + isAsyncFunction, isFunction, isObject, isPromise, @@ -860,15 +866,14 @@ function setupStatefulComponent( const setupContext = (instance.setupContext = setup.length > 1 ? createSetupContext(instance) : null) const reset = setCurrentInstance(instance) - const setupResult = callWithErrorHandling( - setup, - instance, - ErrorCodes.SETUP_FUNCTION, - [ - __DEV__ ? shallowReadonly(instance.props) : instance.props, - setupContext, - ], - ) + const setupResult = ( + isAsyncFunction(setup) + ? callWithAsyncErrorHandling + : callWithErrorHandling + )(setup, instance, ErrorCodes.SETUP_FUNCTION, [ + __DEV__ ? shallowReadonly(instance.props) : instance.props, + setupContext, + ]) const isAsyncSetup = isPromise(setupResult) resetTracking() reset() diff --git a/packages/shared/src/general.ts b/packages/shared/src/general.ts index 9c6a2313240..573f3da50c0 100644 --- a/packages/shared/src/general.ts +++ b/packages/shared/src/general.ts @@ -48,6 +48,8 @@ export const isRegExp = (val: unknown): val is RegExp => toTypeString(val) === '[object RegExp]' export const isFunction = (val: unknown): val is Function => typeof val === 'function' +export const isAsyncFunction = (val: unknown): val is Function => + typeof val === 'function' && toTypeString(val) === '[object AsyncFunction]' export const isString = (val: unknown): val is string => typeof val === 'string' export const isSymbol = (val: unknown): val is symbol => typeof val === 'symbol' export const isObject = (val: unknown): val is Record =>