Subscribe on changes!

Will render comment slots when using `h`

avatar
Jul 16th 2021

What problem does this feature solve?

When using template, slots with only comment or no content rendered will be ignored and the component will render the default contents.

When using h may lose this feature.

I think this may not be a bug, because render-function needs to be managed all things manually.

But currently is no api that can determine whether the contents of slots are effective.

This is a reappear example: https://codesandbox.io/embed/goofy-mcnulty-lume2?fontsize=14&hidenavigation=1&theme=dark

What does the proposed API look like?

import { isEffectiveSlot } from 'vue'

isEffectiveSlot(slot.default)

If there is already such an api, is my negligence.

avatar
Jul 16th 2021

You can just loop through the slot nodes and check if they are all comment nodes:

import { Comment } from 'vue'

const isEffectiveSlot = vnodes => vnodes.some(vnode => vnode.type !== Comment)