From 456939eba767dd74818dc0cceabbc46b95617570 Mon Sep 17 00:00:00 2001 From: Shigma Date: Wed, 14 Sep 2022 12:04:17 +0800 Subject: [PATCH 1/2] fix(runtime-core): check nullability for multi-branch dynamic slots --- packages/runtime-core/src/helpers/createSlots.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/src/helpers/createSlots.ts b/packages/runtime-core/src/helpers/createSlots.ts index 89ea7ac77c8..41dce04b760 100644 --- a/packages/runtime-core/src/helpers/createSlots.ts +++ b/packages/runtime-core/src/helpers/createSlots.ts @@ -31,9 +31,11 @@ export function createSlots( slots[slot.name] = slot.key ? (...args: any[]) => { const res = slot.fn(...args) - // attach branch key so each conditional branch is considered a - // different fragment - ;(res as any).key = slot.key + if (res) { + // attach branch key so each conditional branch is considered a + // different fragment + ;(res as any).key = slot.key + } return res } : slot.fn From cbd71abfd17e39734595716d793e936e9c116f17 Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 25 Sep 2022 19:59:30 +0800 Subject: [PATCH 2/2] test: should check nullability --- .../runtime-core/__tests__/helpers/createSlots.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/runtime-core/__tests__/helpers/createSlots.spec.ts b/packages/runtime-core/__tests__/helpers/createSlots.spec.ts index 891789d048a..2af24380cca 100644 --- a/packages/runtime-core/__tests__/helpers/createSlots.spec.ts +++ b/packages/runtime-core/__tests__/helpers/createSlots.spec.ts @@ -26,6 +26,14 @@ describe('createSlot', () => { expect(ret.key).toBe('1') }) + it('should check nullability', () => { + const slot = (() => {}) as Slot + const dynamicSlot = [{ name: 'descriptor', fn: slot, key: '1' }] + + const actual = createSlots(record, dynamicSlot) + expect(actual).toHaveProperty('descriptor') + }) + it('should add all slots to the record', () => { const dynamicSlot = [ { name: 'descriptor', fn: slot },