Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions packages/runtime-vapor/src/apiRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,38 @@ export function setupComponent(instance: ComponentInternalInstance): void {

let block: Block | undefined

if (
stateOrNode &&
(stateOrNode instanceof Node ||
isArray(stateOrNode) ||
fragmentKey in stateOrNode ||
componentKey in stateOrNode)
) {
// Skip the type check for production since this is only for Dev HMR
if (__DEV__) {
if (
stateOrNode &&
(stateOrNode instanceof Node ||
isArray(stateOrNode) ||
fragmentKey in stateOrNode ||
componentKey in stateOrNode)
) {
block = stateOrNode
} else if (isObject(stateOrNode)) {
instance.setupState = proxyRefs(stateOrNode)
}

if (!block && component.render) {
pauseTracking()
block = callWithErrorHandling(
component.render,
instance,
VaporErrorCodes.RENDER_FUNCTION,
[
instance.setupState, // _ctx
shallowReadonly(props), // $props
instance.emit, // $emit
getAttrsProxy(instance), // $attrs
getSlotsProxy(instance), // $slots
],
)
resetTracking()
}
} else {
block = stateOrNode
} else if (isObject(stateOrNode)) {
instance.setupState = proxyRefs(stateOrNode)
}
if (!block && component.render) {
pauseTracking()
block = callWithErrorHandling(
component.render,
instance,
VaporErrorCodes.RENDER_FUNCTION,
[
instance.setupState, // _ctx
__DEV__ ? shallowReadonly(props) : props, // $props
instance.emit, // $emit
__DEV__ ? getAttrsProxy(instance) : instance.attrs, // $attrs
__DEV__ ? getSlotsProxy(instance) : instance.slots, // $slots
],
)
resetTracking()
}

if (!block) {
Expand Down