exportfunctionsetupComponent(
instance: ComponentInternalInstance,
isSSR =false){
isInSSRComponentSetup = isSSR
const{ props, children }= instance.vnode
const isStateful =isStatefulComponent(instance)initProps(instance, props, isStateful, isSSR)initSlots(instance, children)const setupResult = isStateful
?setupStatefulComponent(instance, isSSR):undefined
isInSSRComponentSetup =falsereturn setupResult
}functionsetupStatefulComponent(
instance: ComponentInternalInstance,
isSSR:boolean){const Component = instance.typeas ComponentOptions
......
instance.accessCache = Object.create(null)// 1. create public instance / render proxy// also mark it raw so it's never observed
instance.proxy =markRaw(newProxy(instance.ctx, PublicInstanceProxyHandlers))if(__DEV__){exposePropsOnRenderContext(instance)}// 2. call setup()const{ setup }= Component
if(setup){const setupContext =(instance.setupContext =
setup.length >1?createSetupContext(instance):null)setCurrentInstance(instance)pauseTracking()const setupResult =callWithErrorHandling(
setup,
instance,
ErrorCodes.SETUP_FUNCTION,[__DEV__ ?shallowReadonly(instance.props): instance.props, setupContext])resetTracking()unsetCurrentInstance()if(isPromise(setupResult)){
setupResult.then(unsetCurrentInstance, unsetCurrentInstance)if(isSSR){// return the promise so server-renderer can wait on itreturn setupResult
.then((resolvedResult:unknown)=>{handleSetupResult(instance, resolvedResult, isSSR)}).catch(e =>{handleError(e, instance, ErrorCodes.SETUP_FUNCTION)})}elseif(__FEATURE_SUSPENSE__){// async setup returned Promise.// bail here and wait for re-entry.
instance.asyncDep = setupResult
if(__DEV__ &&!instance.suspense){const name = Component.name ??'Anonymous'warn(`Component <${name}>: setup function returned a promise, but no `+`<Suspense> boundary was found in the parent component tree. `+`A component with async setup() must be nested in a <Suspense> `+`in order to be rendered.`)}}elseif(__DEV__){warn(`setup() returned a Promise, but the version of Vue you are using `+`does not support it yet.`)}}else{handleSetupResult(instance, setupResult, isSSR)}}else{finishComponentSetup(instance, isSSR)}}