-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Fix when functional component render method retrun null (fix #5536) #5539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/core/vdom/create-element.js
Outdated
@@ -99,7 +99,7 @@ export function _createElement ( | |||
// direct component options / constructor | |||
vnode = createComponent(tag, data, context, children) | |||
} | |||
if (vnode !== undefined) { | |||
if (vnode !== undefined && vnode !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do vnode != null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but the lint forced to use !==
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean if (vnode != null)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you can just use isUndef(vnode)
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flow has some problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyx990803
if use isUndef
like this:
if (isUndef(vnode)) {
return createEmptyVNode()
} else {
if (ns) applyNS(vnode, ns)
return vnode
}
or use isDef
then run test:
> vue@2.3.0 test /Users/xiongyang/workspace/gebilaoxiong/vue
> npm run lint && flow check && npm run test:types && npm run test:cover && npm run test:e2e -- --env phantomjs && npm run test:ssr && npm run test:weex
> vue@2.3.0 lint /Users/xiongyang/workspace/gebilaoxiong/vue
> eslint src build test
src/core/vdom/create-element.js:106
106: return vnode
^^^^^ undefined. This type is incompatible with the expected return type of
51: ): VNode {
^^^^^ VNode
src/core/vdom/create-element.js:111
111: vnode.ns = ns
^^ property `ns`. Property cannot be assigned on possibly undefined value
111: vnode.ns = ns
^^^^^ undefined
src/core/vdom/create-element.js:112
112: if (vnode.tag === 'foreignObject') {
^^^ property `tag`. Property not found in possibly undefined value
112: if (vnode.tag === 'foreignObject') {
^^^^^ undefined
src/core/vdom/create-element.js:116
116: if (Array.isArray(vnode.children)) {
^^^^^^^^ property `children`. Property not found in possibly undefined value
116: if (Array.isArray(vnode.children)) {
^^^^^ undefined
Found 4 errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, flow does not support custom type predicate function.
One workaround is to annotate function isDef(obj): %checks {}
, using internal type check. But strangely flow does not pick up wildcard export.
734d9dd
to
4921068
Compare
6389c71
to
953f397
Compare
bc227fa
to
3a72d5c
Compare
According to my years of |
Dear @gebilaoxiong amigo, your contribution is important for Vue's community. Keep going! Personally I think this is a valid bug and needs to be fixed. So please be patient. I also think the |
Thanks for your reply, I just got a joke 😄 |
Oh, this is closed automatically by GitHub. But I think this pull request needs some polish (use |
src/core/vdom/create-element.js
Outdated
@@ -99,7 +99,7 @@ export function _createElement ( | |||
// direct component options / constructor | |||
vnode = createComponent(tag, data, context, children) | |||
} | |||
if (vnode !== undefined) { | |||
if (vnode != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you can use isDef. Flow will pick it up.
3a72d5c
to
ed691b0
Compare
wow,lucky day!thanks everyone |
issue: #5536
Originally I wanted to use
isDef
but the flow was a bit of a problemWhat kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information: