From e12432ed83c39153ce7ee016e9ce08ddb55f9d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Fri, 1 Sep 2023 13:27:51 +0800 Subject: [PATCH 1/2] fix(runtime-core): fix rendering error when `Element` and `Teleport` children are function --- packages/runtime-core/__tests__/vnode.spec.ts | 8 +++----- packages/runtime-core/src/vnode.ts | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/runtime-core/__tests__/vnode.spec.ts b/packages/runtime-core/__tests__/vnode.spec.ts index 02774aafee4..f75968b3c5e 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 f8cf6652d31..071d4b1f6d5 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -800,8 +800,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 From e46ef713e6a4197a22ac2e73289265aa67c28b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Sat, 25 Nov 2023 08:34:42 +0800 Subject: [PATCH 2/2] test: add dts test --- packages/dts-test/h.test-d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/dts-test/h.test-d.ts b/packages/dts-test/h.test-d.ts index f2e984b49b8..22cd23a814e 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') }) describe('h inference w/ Fragment', () => { @@ -47,6 +48,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