diff --git a/packages/runtime-core/__tests__/componentSlots.spec.ts b/packages/runtime-core/__tests__/componentSlots.spec.ts index 9248a8e6afe..fa6681a7125 100644 --- a/packages/runtime-core/__tests__/componentSlots.spec.ts +++ b/packages/runtime-core/__tests__/componentSlots.spec.ts @@ -167,6 +167,34 @@ describe('component: slots', () => { expect(instance.slots.footer()).toMatchObject([normalizeVNode('footer')]) }) + test('updateSlots: instance.slots should be updated correctly (when slotType becomes null)', async () => { + const flag1 = ref(true) + + let instance: any + const Child = () => { + instance = getCurrentInstance() + return 'child' + } + + const Comp = { + setup() { + return () => [ + h(Child, null, { + default: flag1.value ? () => 'default' : null + }) + ] + } + } + render(h(Comp), nodeOps.createElement('div')) + + expect(instance.slots).toHaveProperty('default') + + flag1.value = false + await nextTick() + + expect(instance.slots).not.toHaveProperty('default') + }) + test('updateSlots: instance.slots should be update correctly (when vnode.shapeFlag is not SLOTS_CHILDREN)', async () => { const flag1 = ref(true) diff --git a/packages/runtime-core/src/componentSlots.ts b/packages/runtime-core/src/componentSlots.ts index 682a107e676..dc948694f7e 100644 --- a/packages/runtime-core/src/componentSlots.ts +++ b/packages/runtime-core/src/componentSlots.ts @@ -204,7 +204,7 @@ export const updateSlots = ( // delete stale slots if (needDeletionCheck) { for (const key in slots) { - if (!isInternalKey(key) && !(key in deletionComparisonTarget)) { + if (!isInternalKey(key) && deletionComparisonTarget[key] == null) { delete slots[key] } }