diff --git a/src/core/vdom/helpers/normalize-children.js b/src/core/vdom/helpers/normalize-children.js index a4622ef44dc..4348e5dffa0 100644 --- a/src/core/vdom/helpers/normalize-children.js +++ b/src/core/vdom/helpers/normalize-children.js @@ -16,6 +16,9 @@ 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) diff --git a/test/unit/features/directives/for.spec.js b/test/unit/features/directives/for.spec.js index 445066284f9..db0470b57b3 100644 --- a/test/unit/features/directives/for.spec.js +++ b/test/unit/features/directives/for.spec.js @@ -484,6 +484,29 @@ describe('Directive v-for', () => { expect(vm.$el.textContent).toBe('12') }) + // #9181 + it('components with v-for and empty list', done => { + const vm = new Vue({ + template: + '
' + + '{{ item }}' + + '
', + data: { + list: undefined + }, + components: { + foo: { + template: '
' + }, + } + }).$mount() + expect(vm.$el.innerHTML).toBe('') + vm.list = [1, 2, 3] + waitForUpdate(() => { + expect(vm.$el.innerHTML).toBe('
1
2
3
') + }).then(done) + }) + const supportsDestructuring = (() => { try { new Function('var { foo } = bar')