From c3831c35e08d155a845e6f5e4fe28a14f81fe50f Mon Sep 17 00:00:00 2001 From: gebilaoxiong Date: Fri, 28 Apr 2017 11:58:38 +0800 Subject: [PATCH 1/3] fix:create empty vnode when functional component return null --- src/core/vdom/create-element.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/vdom/create-element.js b/src/core/vdom/create-element.js index b9c1d0889ac..9f0f23e64c0 100644 --- a/src/core/vdom/create-element.js +++ b/src/core/vdom/create-element.js @@ -99,7 +99,7 @@ export function _createElement ( // direct component options / constructor vnode = createComponent(tag, data, context, children) } - if (vnode !== undefined) { + if (vnode != null) { if (ns) applyNS(vnode, ns) return vnode } else { From af0629c943df4505f8a8870518d1510662d33162 Mon Sep 17 00:00:00 2001 From: gebilaoxiong Date: Fri, 28 Apr 2017 13:24:20 +0800 Subject: [PATCH 2/3] add test --- test/unit/features/options/functional.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/unit/features/options/functional.spec.js b/test/unit/features/options/functional.spec.js index 9345b60e045..9bdff840aca 100644 --- a/test/unit/features/options/functional.spec.js +++ b/test/unit/features/options/functional.spec.js @@ -1,4 +1,5 @@ import Vue from 'vue' +import { createEmptyVNode } from 'core/vdom/vnode' describe('Options functional', () => { it('should work', done => { @@ -167,4 +168,21 @@ describe('Options functional', () => { vm.$destroy() }).then(done) }) + + it('create empty vnode when render return null', () => { + const child = { + functional: true, + render () { + return null + } + } + const vm = new Vue({ + components: { + child + } + }) + const h = vm.$createElement + const vnode = h('child') + expect(vnode).toEqual(createEmptyVNode()) + }) }) From ed691b09da9e3005871add9a849bcd1ed8ba66e2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 29 Apr 2017 14:40:46 +0800 Subject: [PATCH 3/3] use isDef --- src/core/vdom/create-element.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/vdom/create-element.js b/src/core/vdom/create-element.js index 9f0f23e64c0..daa29b80ada 100644 --- a/src/core/vdom/create-element.js +++ b/src/core/vdom/create-element.js @@ -99,7 +99,7 @@ export function _createElement ( // direct component options / constructor vnode = createComponent(tag, data, context, children) } - if (vnode != null) { + if (isDef(vnode)) { if (ns) applyNS(vnode, ns) return vnode } else {