Skip to content

Commit

Permalink
fix: fix empty array edge case in normalizeChildren
Browse files Browse the repository at this point in the history
fix #6790
  • Loading branch information
yyx990803 committed Oct 13, 2017
1 parent f38d44e commit 1f84dd1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/core/vdom/helpers/normalize-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
lastIndex = res.length - 1
last = res[lastIndex]
// nested
if (Array.isArray(c) && c.length > 0) {
c = normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`)
// merge adjacent text nodes
if (isTextNode(c[0]) && isTextNode(last)) {
res[lastIndex] = createTextVNode(last.text + (c[0]: any).text)
c.shift()
if (Array.isArray(c)) {
if (c.length > 0) {
c = normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`)
// merge adjacent text nodes
if (isTextNode(c[0]) && isTextNode(last)) {
res[lastIndex] = createTextVNode(last.text + (c[0]: any).text)
c.shift()
}
res.push.apply(res, c)
}
res.push.apply(res, c)
} else if (isPrimitive(c)) {
if (isTextNode(last)) {
// merge adjacent text nodes
Expand Down
9 changes: 9 additions & 0 deletions test/unit/modules/vdom/patch/edge-cases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,13 @@ describe('vdom patch: edge cases', () => {
expect(vm.$refs.foo.$refs.bar.$el.className).toBe(`hello`)
}).then(done)
})

// #6790
it('should not render undefined for empty nested arrays', () => {
const vm = new Vue({
template: `<div><template v-for="i in emptyArr"></template></div>`,
data: { emptyArr: [] }
}).$mount()
expect(vm.$el.textContent).toBe('')
})
})

0 comments on commit 1f84dd1

Please sign in to comment.