Skip to content

Commit

Permalink
Fix when functional component render method retrun null (fix #5536) (#…
Browse files Browse the repository at this point in the history
…5539)

* fix:create empty vnode when functional component return null

* add test

* use isDef
  • Loading branch information
gebilaoxiong authored and yyx990803 committed Apr 29, 2017
1 parent bb7c543 commit 3b426ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/vdom/create-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function _createElement (
// direct component options / constructor
vnode = createComponent(tag, data, context, children)
}
if (vnode !== undefined) {
if (isDef(vnode)) {
if (ns) applyNS(vnode, ns)
return vnode
} else {
Expand Down
18 changes: 18 additions & 0 deletions test/unit/features/options/functional.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Vue from 'vue'
import { createEmptyVNode } from 'core/vdom/vnode'

describe('Options functional', () => {
it('should work', done => {
Expand Down Expand Up @@ -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())
})
})

0 comments on commit 3b426ef

Please sign in to comment.