fix(custom-elements): work with async component + slots (#4657)

close #4639
This commit is contained in:
edison
2022-04-13 17:58:29 +08:00
committed by GitHub
parent 1612971471
commit f4d2c9fc6a
2 changed files with 37 additions and 2 deletions

View File

@@ -457,5 +457,33 @@ describe('defineCustomElement', () => {
const e = container.childNodes[0] as VueElement
expect(e.shadowRoot!.innerHTML).toBe(`<div>20,number</div>`)
})
test('with slots', async () => {
const E = defineCustomElement(
defineAsyncComponent(() => {
return Promise.resolve({
render(this: any) {
return [
h('div', null, [
renderSlot(this.$slots, 'default', undefined, () => [
h('div', 'fallback')
])
]),
h('div', null, renderSlot(this.$slots, 'named'))
]
}
})
})
)
customElements.define('my-el-async-slots', E)
container.innerHTML = `<my-el-async-slots><span>hi</span></my-el-async-slots>`
await new Promise(r => setTimeout(r))
const e = container.childNodes[0] as VueElement
expect(e.shadowRoot!.innerHTML).toBe(
`<div><slot><div>fallback</div></slot></div><div><slot name="named"></slot></div>`
)
})
})
})