perf(runtime-vapor): `setup()` returning object is only needed in __DEV__ (HMR) (#296)

This commit is contained in:
Rizumu Ayaka 2024-11-30 18:32:16 +08:00 committed by GitHub
parent e61cedf3fd
commit f0361bafbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 31 additions and 25 deletions

View File

@ -55,6 +55,8 @@ export function setupComponent(instance: ComponentInternalInstance): void {
let block: Block | undefined let block: Block | undefined
// Skip the type check for production since this is only for Dev HMR
if (__DEV__) {
if ( if (
stateOrNode && stateOrNode &&
(stateOrNode instanceof Node || (stateOrNode instanceof Node ||
@ -66,6 +68,7 @@ export function setupComponent(instance: ComponentInternalInstance): void {
} else if (isObject(stateOrNode)) { } else if (isObject(stateOrNode)) {
instance.setupState = proxyRefs(stateOrNode) instance.setupState = proxyRefs(stateOrNode)
} }
if (!block && component.render) { if (!block && component.render) {
pauseTracking() pauseTracking()
block = callWithErrorHandling( block = callWithErrorHandling(
@ -74,14 +77,17 @@ export function setupComponent(instance: ComponentInternalInstance): void {
VaporErrorCodes.RENDER_FUNCTION, VaporErrorCodes.RENDER_FUNCTION,
[ [
instance.setupState, // _ctx instance.setupState, // _ctx
__DEV__ ? shallowReadonly(props) : props, // $props shallowReadonly(props), // $props
instance.emit, // $emit instance.emit, // $emit
__DEV__ ? getAttrsProxy(instance) : instance.attrs, // $attrs getAttrsProxy(instance), // $attrs
__DEV__ ? getSlotsProxy(instance) : instance.slots, // $slots getSlotsProxy(instance), // $slots
], ],
) )
resetTracking() resetTracking()
} }
} else {
block = stateOrNode
}
if (!block) { if (!block) {
// TODO: warn no template // TODO: warn no template