fix(slots): should render fallback content when slot content contains no valid nodes (#2485)
fix #2347, fix #2461
This commit is contained in:
@@ -5,7 +5,8 @@ import {
|
||||
createVNode,
|
||||
openBlock,
|
||||
createBlock,
|
||||
Fragment
|
||||
Fragment,
|
||||
createCommentVNode
|
||||
} from '../../src'
|
||||
import { PatchFlags } from '@vue/shared/src'
|
||||
|
||||
@@ -47,4 +48,31 @@ describe('renderSlot', () => {
|
||||
const templateRendered = renderSlot({ default: slot }, 'default')
|
||||
expect(templateRendered.dynamicChildren!.length).toBe(1)
|
||||
})
|
||||
|
||||
// #2347 #2461
|
||||
describe('only render valid slot content', () => {
|
||||
it('should ignore slots that are all comments', () => {
|
||||
let fallback
|
||||
const vnode = renderSlot(
|
||||
{ default: () => [createCommentVNode('foo')] },
|
||||
'default',
|
||||
undefined,
|
||||
() => [(fallback = h('fallback'))]
|
||||
)
|
||||
expect(vnode.children).toEqual([fallback])
|
||||
expect(vnode.patchFlag).toBe(PatchFlags.BAIL)
|
||||
})
|
||||
|
||||
it('should ignore invalid slot content generated by nested slot', () => {
|
||||
let fallback
|
||||
const vnode = renderSlot(
|
||||
{ default: () => [renderSlot({}, 'foo')] },
|
||||
'default',
|
||||
undefined,
|
||||
() => [(fallback = h('fallback'))]
|
||||
)
|
||||
expect(vnode.children).toEqual([fallback])
|
||||
expect(vnode.patchFlag).toBe(PatchFlags.BAIL)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user