Skip to content

Commit 568e824

Browse files
fix(runtime-vapor): properly mount component only with template in production mode (#12727)
Co-authored-by: Evan You <[email protected]>
1 parent 733d6fc commit 568e824

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

packages/runtime-vapor/__tests__/component.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ describe('component', () => {
282282
expect(i.scope.effects.length).toBe(0)
283283
})
284284

285+
test('should mount component only with template in production mode', () => {
286+
__DEV__ = false
287+
const { component: Child } = define({
288+
render() {
289+
return template('<div> HI </div>', true)()
290+
},
291+
})
292+
293+
const { host } = define({
294+
setup() {
295+
return createComponent(Child, null, null, true)
296+
},
297+
}).render()
298+
299+
expect(host.innerHTML).toBe('<div> HI </div>')
300+
__DEV__ = true
301+
})
302+
285303
it('warn if functional vapor component not return a block', () => {
286304
define(() => {
287305
return () => {}

packages/runtime-vapor/src/component.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,18 @@ export function createComponent(
212212
}
213213
}
214214
} else {
215-
// in prod result can only be block
216-
instance.block = setupResult as Block
215+
// component has a render function but no setup function
216+
// (typically components with only a template and no state)
217+
if (!setupFn && component.render) {
218+
instance.block = callWithErrorHandling(
219+
component.render,
220+
instance,
221+
ErrorCodes.RENDER_FUNCTION,
222+
)
223+
} else {
224+
// in prod result can only be block
225+
instance.block = setupResult as Block
226+
}
217227
}
218228

219229
// single root, inherit attrs

0 commit comments

Comments
 (0)