Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): delete undefined stale slots #7383

Closed
wants to merge 1 commit into from
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
28 changes: 28 additions & 0 deletions packages/runtime-core/__tests__/componentSlots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
Expand Down