From: edison Date: Wed, 29 Jan 2025 04:30:00 +0000 (+0800) Subject: fix(runtime-vapor): properly mount component only with template in production mode... X-Git-Tag: v3.6.0-alpha.1~16^2~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=568e8242004a66a49db667ff07566c68caa8175e;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-vapor): properly mount component only with template in production mode (#12727) Co-authored-by: Evan You --- diff --git a/packages/runtime-vapor/__tests__/component.spec.ts b/packages/runtime-vapor/__tests__/component.spec.ts index a4af5be7ab..c9f3a5ffd6 100644 --- a/packages/runtime-vapor/__tests__/component.spec.ts +++ b/packages/runtime-vapor/__tests__/component.spec.ts @@ -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('
HI
', true)() + }, + }) + + const { host } = define({ + setup() { + return createComponent(Child, null, null, true) + }, + }).render() + + expect(host.innerHTML).toBe('
HI
') + __DEV__ = true + }) + it('warn if functional vapor component not return a block', () => { define(() => { return () => {} diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index abe72e79cf..3e5d4fc2d2 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -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