Skip to content
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

types: allow (almost) anything in VNodeChildrenArrayContents #8498

Closed
KaelWD opened this issue Jul 16, 2018 · 1 comment · Fixed by #9154
Closed

types: allow (almost) anything in VNodeChildrenArrayContents #8498

KaelWD opened this issue Jul 16, 2018 · 1 comment · Fixed by #9154

Comments

@KaelWD
Copy link
Contributor

KaelWD commented Jul 16, 2018

What problem does this feature solve?

The Vue runtime allows pretty much anything to be put into the children array, and simply strips away boolean | null | undefined:

if (isUndef(c) || typeof c === 'boolean') continue

The types on the other hand only allow string, VNode, or another nested array, which means we can't use short-circuit expressions to conditionally render things.

// Doesn't work - `false` is not allowed
return h('div', data, [
  this.enableSomething && h(Something)
])

// We have to do
const children: VNodeChildrenArrayContents = []
this.enableSomething && children.push(h(Something))
return h('div', data, children)

// Or
return h('div', data, [
  this.enableSomething ? h(Something) : []
])

What does the proposed API look like?

Add a separate type for createElement that also allows boolean | null | undefined, that way vnode.children can still be the current normalised version.

@KaelWD
Copy link
Contributor Author

KaelWD commented Dec 3, 2018

This is needed even more since #8946 was merged, now you can't even do

h('div', [this.$slots.default])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants