Browse Source

fix(v-slot): fix scoped slot normalization combined with v-if (#12104)

dev
Eduardo San Martin Morote 4 years ago
committed by GitHub
parent
commit
38f71de380
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/core/vdom/helpers/normalize-scoped-slots.js
  2. 14
      test/unit/features/component/component-slot.spec.js

4
src/core/vdom/helpers/normalize-scoped-slots.js

@ -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
}

14
test/unit/features/component/component-slot.spec.js

@ -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>`)
})
})

Loading…
Cancel
Save