Description
The slotted content appears to just be a clone of whatever is inside the web-components body. For example if I had:
<my-first-web-component>
<button>Something</button>
</my-first-web-component>
If I created that button programatically and inserted it inside the wrapped web component then this wrapper will simply pick that up and create VNode
out of it for Vue to render. This is bad because if I attach an event listener to this element then it simply wont ever be called as the element rendered is not the same as the one I'm attaching a listener to.
I'm not certain on a good solution though, I think this needs to be handled outside of Vue. Possibly instead of creating a VNode from the element itself we could render a native slot element here and leave the slot handling up to the browser/polyfill where this may not be a problem?
Modified toVNode
method to understand the 'potential' solution above:
function toVNode (h, node) {
if (node.nodeType === 3) {
return node.data.trim() ? node.data : null
} else if (node.nodeType === 1) {
const slotName = node.getAttribute('slot')
return h('slot', slotName ? {
slot: slotName,
attrs: { name: slotName }
} : null)
} else {
return null
}
}