This commit is contained in:
zhiyuanzmj 2025-06-26 16:10:58 +08:00 committed by GitHub
commit 5e8787216d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 1 deletions

View File

@ -28,6 +28,7 @@ export enum ErrorCodes {
SCHEDULER,
COMPONENT_UPDATE,
APP_UNMOUNT_CLEANUP,
RENDER_SLOTS,
}
export const ErrorTypeStrings: Record<ErrorTypes, string> = {
@ -62,6 +63,7 @@ export const ErrorTypeStrings: Record<ErrorTypes, string> = {
[ErrorCodes.SCHEDULER]: 'scheduler flush',
[ErrorCodes.COMPONENT_UPDATE]: 'component update',
[ErrorCodes.APP_UNMOUNT_CLEANUP]: 'app unmount cleanup function',
[ErrorCodes.RENDER_SLOTS]: 'render slots',
}
export type ErrorTypes = LifecycleHooks | ErrorCodes | WatchErrorCodes

View File

@ -1,4 +1,5 @@
import {
Fragment,
type Ref,
inject,
nextTick,
@ -352,4 +353,16 @@ describe('component', () => {
'Vapor component setup() returned non-block value, and has no render function',
).toHaveBeenWarned()
})
it('Fragment slots should be rendered', () => {
const { host } = define({
setup() {
return createComponent(Fragment as any, null, {
default: () => template('HI', true)(),
})
},
}).render()
expect(host.innerHTML).toBe('HI')
})
})

View File

@ -5,6 +5,7 @@ import {
type EmitFn,
type EmitsOptions,
ErrorCodes,
Fragment,
type GenericAppContext,
type GenericComponentInstance,
type LifecycleHook,
@ -213,7 +214,18 @@ export function createComponent(
]) || EMPTY_OBJ
: EMPTY_OBJ
if (__DEV__ && !isBlock(setupResult)) {
if (component === Fragment && rawSlots) {
const defaultSlot = getSlot(rawSlots as RawSlots, 'default')
if (defaultSlot) {
instance.block = callWithErrorHandling(
defaultSlot,
instance,
ErrorCodes.RENDER_SLOTS,
)
} else {
instance.block = []
}
} else if (__DEV__ && !isBlock(setupResult)) {
if (isFunction(component)) {
warn(`Functional vapor component must return a block directly.`)
instance.block = []