Skip to content

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

Merged
merged 3 commits into from
Apr 29, 2017

Conversation

gebilaoxiong
Copy link
Member

@gebilaoxiong gebilaoxiong commented Apr 27, 2017

issue: #5536

Originally I wanted to use isDef but the flow was a bit of a problem

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

@@ -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) {
Copy link
Member

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

Copy link
Member Author

@gebilaoxiong gebilaoxiong Apr 27, 2017

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 !==

Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flow has some problems

Copy link
Member Author

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

Copy link
Member

@HerringtonDarkholme HerringtonDarkholme Apr 28, 2017

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.

facebook/flow#34

One workaround is to annotate function isDef(obj): %checks {}, using internal type check. But strangely flow does not pick up wildcard export.

@gebilaoxiong gebilaoxiong force-pushed the fix_render_output_null branch 2 times, most recently from 734d9dd to 4921068 Compare April 27, 2017 16:31
@gebilaoxiong gebilaoxiong changed the title fix:when render method retrun null Fix when render method retrun null (fix #5536) Apr 27, 2017
@gebilaoxiong gebilaoxiong force-pushed the fix_render_output_null branch 2 times, most recently from 6389c71 to 953f397 Compare April 28, 2017 03:52
@gebilaoxiong gebilaoxiong changed the title Fix when render method retrun null (fix #5536) Fix when functional component render method retrun null (fix #5536) Apr 28, 2017
@gebilaoxiong gebilaoxiong force-pushed the fix_render_output_null branch 3 times, most recently from bc227fa to 3a72d5c Compare April 28, 2017 05:24
@gebilaoxiong
Copy link
Member Author

gebilaoxiong commented Apr 28, 2017

According to my years of PR was closed experience, I feel this time again to be closed 😢

@HerringtonDarkholme
Copy link
Member

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 isDef flow problem can be fixed. I'm working on it.

@gebilaoxiong
Copy link
Member Author

@HerringtonDarkholme

Thanks for your reply, I just got a joke 😄

HerringtonDarkholme added a commit to HerringtonDarkholme/vue that referenced this pull request Apr 28, 2017
@yyx990803 yyx990803 closed this in bb7c543 Apr 29, 2017
@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Apr 29, 2017

Oh, this is closed automatically by GitHub.

But I think this pull request needs some polish (use isDef) and then it can be ready. Ping @gebilaoxiong

@@ -99,7 +99,7 @@ export function _createElement (
// direct component options / constructor
vnode = createComponent(tag, data, context, children)
}
if (vnode !== undefined) {
if (vnode != null) {

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.

@yyx990803 yyx990803 force-pushed the fix_render_output_null branch from 3a72d5c to ed691b0 Compare April 29, 2017 06:42
@yyx990803 yyx990803 merged commit 3b426ef into vuejs:dev Apr 29, 2017
@gebilaoxiong
Copy link
Member Author

gebilaoxiong commented Apr 30, 2017

wow,lucky day!thanks everyone

@gebilaoxiong gebilaoxiong deleted the fix_render_output_null branch April 30, 2017 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants