fix(runtime-vapor): properly mount component only with template in production mode (#12727)

Co-authored-by: Evan You <evan@vuejs.org>
This commit is contained in:
edison 2025-01-29 12:30:00 +08:00 committed by GitHub
parent 733d6fc13d
commit 568e824200
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View 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 () => {}

View 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