]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(runtime-vapor): support HMR for non-compiled setup component (#13102)
authorzhiyuanzmj <260480378@qq.com>
Thu, 10 Jul 2025 00:30:25 +0000 (08:30 +0800)
committerGitHub <noreply@github.com>
Thu, 10 Jul 2025 00:30:25 +0000 (17:30 -0700)
packages/runtime-vapor/src/component.ts

index af15133dbe54f7510deb7abc2bf85e88f76f6250..ab5f65de7755e3d28714a6a6da011d04d47c759c 100644 (file)
@@ -188,6 +188,14 @@ export function createComponent(
     appContext,
   )
 
+  // HMR
+  if (__DEV__ && component.__hmrId) {
+    registerHMR(instance)
+    instance.isSingleRoot = isSingleRoot
+    instance.hmrRerender = hmrRerender.bind(null, instance)
+    instance.hmrReload = hmrReload.bind(null, instance)
+  }
+
   if (__DEV__) {
     pushWarningContext(instance)
     startMeasure(instance, `init`)
@@ -227,14 +235,6 @@ export function createComponent(
       // TODO make the proxy warn non-existent property access during dev
       instance.setupState = proxyRefs(setupResult)
       devRender(instance)
-
-      // HMR
-      if (component.__hmrId) {
-        registerHMR(instance)
-        instance.isSingleRoot = isSingleRoot
-        instance.hmrRerender = hmrRerender.bind(null, instance)
-        instance.hmrReload = hmrReload.bind(null, instance)
-      }
     }
   } else {
     // component has a render function but no setup function
@@ -291,18 +291,33 @@ export let isApplyingFallthroughProps = false
  */
 export function devRender(instance: VaporComponentInstance): void {
   instance.block =
-    callWithErrorHandling(
-      instance.type.render!,
-      instance,
-      ErrorCodes.RENDER_FUNCTION,
-      [
-        instance.setupState,
-        instance.props,
-        instance.emit,
-        instance.attrs,
-        instance.slots,
-      ],
-    ) || []
+    (instance.type.render
+      ? callWithErrorHandling(
+          instance.type.render,
+          instance,
+          ErrorCodes.RENDER_FUNCTION,
+          [
+            instance.setupState,
+            instance.props,
+            instance.emit,
+            instance.attrs,
+            instance.slots,
+          ],
+        )
+      : callWithErrorHandling(
+          isFunction(instance.type) ? instance.type : instance.type.setup!,
+          instance,
+          ErrorCodes.SETUP_FUNCTION,
+          [
+            instance.props,
+            {
+              slots: instance.slots,
+              attrs: instance.attrs,
+              emit: instance.emit,
+              expose: instance.expose,
+            },
+          ],
+        )) || []
 }
 
 const emptyContext: GenericAppContext = {