Skip to content
Closed
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
2 changes: 2 additions & 0 deletions packages/runtime-core/src/errorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum ErrorCodes {
SCHEDULER,
COMPONENT_UPDATE,
APP_UNMOUNT_CLEANUP,
RENDER_SLOTS,
}

export const ErrorTypeStrings: Record<ErrorTypes, string> = {
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions packages/runtime-vapor/__tests__/component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
type EffectScope,
Fragment,
ReactiveEffect,
type Ref,
inject,
Expand Down Expand Up @@ -354,6 +355,18 @@ 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')
})
})

function getEffectsCount(scope: EffectScope): number {
Expand Down
13 changes: 12 additions & 1 deletion packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type EmitFn,
type EmitsOptions,
ErrorCodes,
Fragment,
type GenericAppContext,
type GenericComponentInstance,
type LifecycleHook,
Expand Down Expand Up @@ -219,7 +220,17 @@ export function createComponent(
]) || EMPTY_OBJ
: EMPTY_OBJ

if (__DEV__ && !isBlock(setupResult)) {
if (component === Fragment) {
if (instance.slots.default) {
instance.block = callWithErrorHandling(
instance.slots.default,
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 = []
Expand Down