Skip to content

Commit

Permalink
fix: fix single v-for child optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 11, 2018
1 parent 4e97548 commit 847e493
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/core/instance/render-helpers/render-list.js
Expand Up @@ -32,8 +32,9 @@ export function renderList (
ret[i] = render(val[key], key, i)
}
}
if (isDef(ret)) {
(ret: any)._isVList = true
if (!isDef(ret)) {
ret = []
}
(ret: any)._isVList = true
return ret
}
3 changes: 0 additions & 3 deletions src/core/vdom/helpers/normalize-children.js
Expand Up @@ -16,9 +16,6 @@ import { isFalse, isTrue, isDef, isUndef, isPrimitive } from 'shared/util'
// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep
// because functional components already normalize their own children.
export function simpleNormalizeChildren (children: any) {
if (!Array.isArray(children)) {
return
}
for (let i = 0; i < children.length; i++) {
if (Array.isArray(children[i])) {
return Array.prototype.concat.apply([], children)
Expand Down
19 changes: 18 additions & 1 deletion test/unit/features/directives/for.spec.js
Expand Up @@ -489,7 +489,7 @@ describe('Directive v-for', () => {
const vm = new Vue({
template:
'<div attr>' +
'<foo v-for="item in list">{{ item }}</foo>' +
'<foo v-for="item in list" :key="item">{{ item }}</foo>' +
'</div>',
data: {
list: undefined
Expand All @@ -507,6 +507,23 @@ describe('Directive v-for', () => {
}).then(done)
})

it('elements with v-for and empty list', done => {
const vm = new Vue({
template:
'<div attr>' +
'<div v-for="item in list">{{ item }}</div>' +
'</div>',
data: {
list: undefined
}
}).$mount()
expect(vm.$el.innerHTML).toBe('')
vm.list = [1, 2, 3]
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe('<div>1</div><div>2</div><div>3</div>')
}).then(done)
})

const supportsDestructuring = (() => {
try {
new Function('var { foo } = bar')
Expand Down

0 comments on commit 847e493

Please sign in to comment.