Skip to content

Commit

Permalink
chore: handle error with async setup
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Dec 23, 2024
1 parent e613f0c commit 743e6b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -67,6 +72,7 @@ import {
extend,
getGlobalThis,
isArray,
isAsyncFunction,
isFunction,
isObject,
isPromise,
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any> =>
Expand Down

0 comments on commit 743e6b5

Please sign in to comment.