Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-vapor): properly mount template-only components in production #12727

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/runtime-vapor/__tests__/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {}
Expand Down
14 changes: 12 additions & 2 deletions packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading