Skip to content

Commit 1f84dd1

Browse files
committed
fix: fix empty array edge case in normalizeChildren
fix #6790
1 parent f38d44e commit 1f84dd1

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/core/vdom/helpers/normalize-children.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
4949
lastIndex = res.length - 1
5050
last = res[lastIndex]
5151
// nested
52-
if (Array.isArray(c) && c.length > 0) {
53-
c = normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`)
54-
// merge adjacent text nodes
55-
if (isTextNode(c[0]) && isTextNode(last)) {
56-
res[lastIndex] = createTextVNode(last.text + (c[0]: any).text)
57-
c.shift()
52+
if (Array.isArray(c)) {
53+
if (c.length > 0) {
54+
c = normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`)
55+
// merge adjacent text nodes
56+
if (isTextNode(c[0]) && isTextNode(last)) {
57+
res[lastIndex] = createTextVNode(last.text + (c[0]: any).text)
58+
c.shift()
59+
}
60+
res.push.apply(res, c)
5861
}
59-
res.push.apply(res, c)
6062
} else if (isPrimitive(c)) {
6163
if (isTextNode(last)) {
6264
// merge adjacent text nodes

test/unit/modules/vdom/patch/edge-cases.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,13 @@ describe('vdom patch: edge cases', () => {
189189
expect(vm.$refs.foo.$refs.bar.$el.className).toBe(`hello`)
190190
}).then(done)
191191
})
192+
193+
// #6790
194+
it('should not render undefined for empty nested arrays', () => {
195+
const vm = new Vue({
196+
template: `<div><template v-for="i in emptyArr"></template></div>`,
197+
data: { emptyArr: [] }
198+
}).$mount()
199+
expect(vm.$el.textContent).toBe('')
200+
})
192201
})

0 commit comments

Comments
 (0)