]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf(runtime-vapor): `setup()` returning object is only needed in __DEV__ (HMR) ...
authorRizumu Ayaka <rizumu@ayaka.moe>
Sat, 30 Nov 2024 10:32:16 +0000 (18:32 +0800)
committerGitHub <noreply@github.com>
Sat, 30 Nov 2024 10:32:16 +0000 (18:32 +0800)
packages/runtime-vapor/src/apiRender.ts

index fe06beb65521500b8b2d30f916f8d5237435bf36..408a7928d03339dbdee7b8af4fe54b0b691f5d08 100644 (file)
@@ -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) {