Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(v-slot): fix scoped slot normalization combined with v-if (#12104)
  • Loading branch information
posva committed Jun 2, 2021
1 parent 67901e7 commit 38f71de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/vdom/helpers/normalize-scoped-slots.js
Expand Up @@ -61,10 +61,10 @@ function normalizeScopedSlot(normalSlots, key, fn) {
res = res && typeof res === 'object' && !Array.isArray(res)
? [res] // single vnode
: normalizeChildren(res)
let vnode: VNode = res && res[0]
let vnode: ?VNode = res && res[0]
return res && (
!vnode ||
(vnode.isComment && !isAsyncPlaceholder(vnode)) // #9658, #10391
(res.length === 1 && vnode.isComment && !isAsyncPlaceholder(vnode)) // #9658, #10391
) ? undefined
: res
}
Expand Down
14 changes: 14 additions & 0 deletions test/unit/features/component/component-slot.spec.js
Expand Up @@ -986,4 +986,18 @@ describe('Component slot', () => {
expect(vm.$el.firstChild.innerHTML).toBe('<span><b>2</b></span>')
}).then(done)
})

// #12102
it('v-if inside scoped slot', () => {
const vm = new Vue({
template: `<test><template #custom><span v-if="false">a</span><span>b</span></template></test>`,
components: {
test: {
template: `<div><slot name="custom"/></div>`
}
}
}).$mount()

expect(vm.$el.innerHTML).toBe(`<!----><span>b</span>`)
})
})

0 comments on commit 38f71de

Please sign in to comment.