Skip to content

Commit f0361ba

Browse files
authored
perf(runtime-vapor): setup() returning object is only needed in __DEV__ (HMR) (#296)
1 parent e61cedf commit f0361ba

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

packages/runtime-vapor/src/apiRender.ts

+31-25
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,38 @@ export function setupComponent(instance: ComponentInternalInstance): void {
5555

5656
let block: Block | undefined
5757

58-
if (
59-
stateOrNode &&
60-
(stateOrNode instanceof Node ||
61-
isArray(stateOrNode) ||
62-
fragmentKey in stateOrNode ||
63-
componentKey in stateOrNode)
64-
) {
58+
// Skip the type check for production since this is only for Dev HMR
59+
if (__DEV__) {
60+
if (
61+
stateOrNode &&
62+
(stateOrNode instanceof Node ||
63+
isArray(stateOrNode) ||
64+
fragmentKey in stateOrNode ||
65+
componentKey in stateOrNode)
66+
) {
67+
block = stateOrNode
68+
} else if (isObject(stateOrNode)) {
69+
instance.setupState = proxyRefs(stateOrNode)
70+
}
71+
72+
if (!block && component.render) {
73+
pauseTracking()
74+
block = callWithErrorHandling(
75+
component.render,
76+
instance,
77+
VaporErrorCodes.RENDER_FUNCTION,
78+
[
79+
instance.setupState, // _ctx
80+
shallowReadonly(props), // $props
81+
instance.emit, // $emit
82+
getAttrsProxy(instance), // $attrs
83+
getSlotsProxy(instance), // $slots
84+
],
85+
)
86+
resetTracking()
87+
}
88+
} else {
6589
block = stateOrNode
66-
} else if (isObject(stateOrNode)) {
67-
instance.setupState = proxyRefs(stateOrNode)
68-
}
69-
if (!block && component.render) {
70-
pauseTracking()
71-
block = callWithErrorHandling(
72-
component.render,
73-
instance,
74-
VaporErrorCodes.RENDER_FUNCTION,
75-
[
76-
instance.setupState, // _ctx
77-
__DEV__ ? shallowReadonly(props) : props, // $props
78-
instance.emit, // $emit
79-
__DEV__ ? getAttrsProxy(instance) : instance.attrs, // $attrs
80-
__DEV__ ? getSlotsProxy(instance) : instance.slots, // $slots
81-
],
82-
)
83-
resetTracking()
8490
}
8591

8692
if (!block) {

0 commit comments

Comments
 (0)