Skip to content

Commit 847e493

Browse files
committedDec 11, 2018
fix: fix single v-for child optimization
1 parent 4e97548 commit 847e493

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed
 

‎src/core/instance/render-helpers/render-list.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ export function renderList (
3232
ret[i] = render(val[key], key, i)
3333
}
3434
}
35-
if (isDef(ret)) {
36-
(ret: any)._isVList = true
35+
if (!isDef(ret)) {
36+
ret = []
3737
}
38+
(ret: any)._isVList = true
3839
return ret
3940
}

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

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ import { isFalse, isTrue, isDef, isUndef, isPrimitive } from 'shared/util'
1616
// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep
1717
// because functional components already normalize their own children.
1818
export function simpleNormalizeChildren (children: any) {
19-
if (!Array.isArray(children)) {
20-
return
21-
}
2219
for (let i = 0; i < children.length; i++) {
2320
if (Array.isArray(children[i])) {
2421
return Array.prototype.concat.apply([], children)

‎test/unit/features/directives/for.spec.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ describe('Directive v-for', () => {
489489
const vm = new Vue({
490490
template:
491491
'<div attr>' +
492-
'<foo v-for="item in list">{{ item }}</foo>' +
492+
'<foo v-for="item in list" :key="item">{{ item }}</foo>' +
493493
'</div>',
494494
data: {
495495
list: undefined
@@ -507,6 +507,23 @@ describe('Directive v-for', () => {
507507
}).then(done)
508508
})
509509

510+
it('elements with v-for and empty list', done => {
511+
const vm = new Vue({
512+
template:
513+
'<div attr>' +
514+
'<div v-for="item in list">{{ item }}</div>' +
515+
'</div>',
516+
data: {
517+
list: undefined
518+
}
519+
}).$mount()
520+
expect(vm.$el.innerHTML).toBe('')
521+
vm.list = [1, 2, 3]
522+
waitForUpdate(() => {
523+
expect(vm.$el.innerHTML).toBe('<div>1</div><div>2</div><div>3</div>')
524+
}).then(done)
525+
})
526+
510527
const supportsDestructuring = (() => {
511528
try {
512529
new Function('var { foo } = bar')

0 commit comments

Comments
 (0)
Please sign in to comment.