Skip to content

Commit 3b426ef

Browse files
gebilaoxiongyyx990803
authored andcommitted
Fix when functional component render method retrun null (fix vuejs#5536) (vuejs#5539)
* fix:create empty vnode when functional component return null * add test * use isDef
1 parent bb7c543 commit 3b426ef

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/core/vdom/create-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function _createElement (
9999
// direct component options / constructor
100100
vnode = createComponent(tag, data, context, children)
101101
}
102-
if (vnode !== undefined) {
102+
if (isDef(vnode)) {
103103
if (ns) applyNS(vnode, ns)
104104
return vnode
105105
} else {

test/unit/features/options/functional.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Vue from 'vue'
2+
import { createEmptyVNode } from 'core/vdom/vnode'
23

34
describe('Options functional', () => {
45
it('should work', done => {
@@ -167,4 +168,21 @@ describe('Options functional', () => {
167168
vm.$destroy()
168169
}).then(done)
169170
})
171+
172+
it('create empty vnode when render return null', () => {
173+
const child = {
174+
functional: true,
175+
render () {
176+
return null
177+
}
178+
}
179+
const vm = new Vue({
180+
components: {
181+
child
182+
}
183+
})
184+
const h = vm.$createElement
185+
const vnode = h('child')
186+
expect(vnode).toEqual(createEmptyVNode())
187+
})
170188
})

0 commit comments

Comments
 (0)