diff --git a/packages/dts-test/h.test-d.ts b/packages/dts-test/h.test-d.ts index 62e619c22bd..0bfac779ec6 100644 --- a/packages/dts-test/h.test-d.ts +++ b/packages/dts-test/h.test-d.ts @@ -32,6 +32,7 @@ describe('h inference w/ element', () => { // slots const slots = { default: () => {} } // RawSlots h('div', {}, slots) + h('div', {}, () => 'hello') // events h('div', { onClick: e => { @@ -58,6 +59,7 @@ describe('h inference w/ Fragment', () => { describe('h inference w/ Teleport', () => { h(Teleport, { to: '#foo' }, 'hello') h(Teleport, { to: '#foo' }, { default() {} }) + h(Teleport, { to: '#foo' }, () => 'hello') // @ts-expect-error h(Teleport) // @ts-expect-error diff --git a/packages/runtime-core/__tests__/vnode.spec.ts b/packages/runtime-core/__tests__/vnode.spec.ts index 653613ddb2e..19266bbec68 100644 --- a/packages/runtime-core/__tests__/vnode.spec.ts +++ b/packages/runtime-core/__tests__/vnode.spec.ts @@ -120,8 +120,6 @@ describe('vnode', () => { }) describe('children normalization', () => { - const nop = vi.fn - test('null', () => { const vnode = createVNode('p', null, null) expect(vnode.children).toBe(null) @@ -145,10 +143,10 @@ describe('vnode', () => { }) test('function', () => { - const vnode = createVNode('p', null, nop) - expect(vnode.children).toMatchObject({ default: nop }) + const vnode = createVNode('p', null, () => 'foo') + expect(vnode.children).toBe('foo') expect(vnode.shapeFlag).toBe( - ShapeFlags.ELEMENT | ShapeFlags.SLOTS_CHILDREN, + ShapeFlags.ELEMENT | ShapeFlags.TEXT_CHILDREN, ) }) diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 178ceec41bd..8404564c46b 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -810,8 +810,8 @@ export function normalizeChildren(vnode: VNode, children: unknown) { } } } else if (isFunction(children)) { - children = { default: children, _ctx: currentRenderingInstance } - type = ShapeFlags.SLOTS_CHILDREN + normalizeChildren(vnode, { default: children }) + return } else { children = String(children) // force teleport children to array so it can be moved around