From 38f71de380d566e4eef60968a8eca6bd6f482dd5 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 2 Jun 2021 14:44:18 +0200 Subject: [PATCH] fix(v-slot): fix scoped slot normalization combined with v-if (#12104) --- src/core/vdom/helpers/normalize-scoped-slots.js | 4 ++-- .../unit/features/component/component-slot.spec.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/core/vdom/helpers/normalize-scoped-slots.js b/src/core/vdom/helpers/normalize-scoped-slots.js index 15ab396d..13df231f 100644 --- a/src/core/vdom/helpers/normalize-scoped-slots.js +++ b/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 } diff --git a/test/unit/features/component/component-slot.spec.js b/test/unit/features/component/component-slot.spec.js index c6e20e49..4412a1f0 100644 --- a/test/unit/features/component/component-slot.spec.js +++ b/test/unit/features/component/component-slot.spec.js @@ -986,4 +986,18 @@ describe('Component slot', () => { expect(vm.$el.firstChild.innerHTML).toBe('2') }).then(done) }) + + // #12102 + it('v-if inside scoped slot', () => { + const vm = new Vue({ + template: ``, + components: { + test: { + template: `
` + } + } + }).$mount() + + expect(vm.$el.innerHTML).toBe(`b`) + }) })