]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-vapor): properly mount component only with template in production mode...
authoredison <daiwei521@126.com>
Wed, 29 Jan 2025 04:30:00 +0000 (12:30 +0800)
committerGitHub <noreply@github.com>
Wed, 29 Jan 2025 04:30:00 +0000 (12:30 +0800)
Co-authored-by: Evan You <evan@vuejs.org>
packages/runtime-vapor/__tests__/component.spec.ts
packages/runtime-vapor/src/component.ts

index a4af5be7ab192ba5b11628ab889262ce30553f77..c9f3a5ffd68c1cd9d135c6658790a2ebda8f5ed2 100644 (file)
@@ -282,6 +282,24 @@ describe('component', () => {
     expect(i.scope.effects.length).toBe(0)
   })
 
+  test('should mount component only with template in production mode', () => {
+    __DEV__ = false
+    const { component: Child } = define({
+      render() {
+        return template('<div> HI </div>', true)()
+      },
+    })
+
+    const { host } = define({
+      setup() {
+        return createComponent(Child, null, null, true)
+      },
+    }).render()
+
+    expect(host.innerHTML).toBe('<div> HI </div>')
+    __DEV__ = true
+  })
+
   it('warn if functional vapor component not return a block', () => {
     define(() => {
       return () => {}
index abe72e79cfe78b48eb1a0b616245531f30387a8d..3e5d4fc2d28fd4c0d7fee1bc72c992d747d2b050 100644 (file)
@@ -212,8 +212,18 @@ export function createComponent(
       }
     }
   } else {
-    // in prod result can only be block
-    instance.block = setupResult as Block
+    // component has a render function but no setup function
+    // (typically components with only a template and no state)
+    if (!setupFn && component.render) {
+      instance.block = callWithErrorHandling(
+        component.render,
+        instance,
+        ErrorCodes.RENDER_FUNCTION,
+      )
+    } else {
+      // in prod result can only be block
+      instance.block = setupResult as Block
+    }
   }
 
   // single root, inherit attrs