Skip to content

Commit 743e6b5

Browse files
committed
chore: handle error with async setup
1 parent e613f0c commit 743e6b5

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

packages/runtime-core/src/component.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ import {
3535
initSlots,
3636
} from './componentSlots'
3737
import { warn } from './warning'
38-
import { ErrorCodes, callWithErrorHandling, handleError } from './errorHandling'
38+
import {
39+
ErrorCodes,
40+
callWithAsyncErrorHandling,
41+
callWithErrorHandling,
42+
handleError,
43+
} from './errorHandling'
3944
import {
4045
type AppConfig,
4146
type AppContext,
@@ -67,6 +72,7 @@ import {
6772
extend,
6873
getGlobalThis,
6974
isArray,
75+
isAsyncFunction,
7076
isFunction,
7177
isObject,
7278
isPromise,
@@ -860,15 +866,14 @@ function setupStatefulComponent(
860866
const setupContext = (instance.setupContext =
861867
setup.length > 1 ? createSetupContext(instance) : null)
862868
const reset = setCurrentInstance(instance)
863-
const setupResult = callWithErrorHandling(
864-
setup,
865-
instance,
866-
ErrorCodes.SETUP_FUNCTION,
867-
[
868-
__DEV__ ? shallowReadonly(instance.props) : instance.props,
869-
setupContext,
870-
],
871-
)
869+
const setupResult = (
870+
isAsyncFunction(setup)
871+
? callWithAsyncErrorHandling
872+
: callWithErrorHandling
873+
)(setup, instance, ErrorCodes.SETUP_FUNCTION, [
874+
__DEV__ ? shallowReadonly(instance.props) : instance.props,
875+
setupContext,
876+
])
872877
const isAsyncSetup = isPromise(setupResult)
873878
resetTracking()
874879
reset()

packages/shared/src/general.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export const isRegExp = (val: unknown): val is RegExp =>
4848
toTypeString(val) === '[object RegExp]'
4949
export const isFunction = (val: unknown): val is Function =>
5050
typeof val === 'function'
51+
export const isAsyncFunction = (val: unknown): val is Function =>
52+
typeof val === 'function' && toTypeString(val) === '[object AsyncFunction]'
5153
export const isString = (val: unknown): val is string => typeof val === 'string'
5254
export const isSymbol = (val: unknown): val is symbol => typeof val === 'symbol'
5355
export const isObject = (val: unknown): val is Record<any, any> =>

0 commit comments

Comments
 (0)