fix(custom-element): ensure configureApp is applied to async component (#12607)
close #12448
This commit is contained in:
parent
73055d8d95
commit
5ba1afba09
|
@ -1566,6 +1566,29 @@ describe('defineCustomElement', () => {
|
|||
expect(e.shadowRoot?.innerHTML).toBe('<div>app-injected</div>')
|
||||
})
|
||||
|
||||
// #12448
|
||||
test('work with async component', async () => {
|
||||
const AsyncComp = defineAsyncComponent(() => {
|
||||
return Promise.resolve({
|
||||
render() {
|
||||
const msg: string | undefined = inject('msg')
|
||||
return h('div', {}, msg)
|
||||
},
|
||||
} as any)
|
||||
})
|
||||
const E = defineCustomElement(AsyncComp, {
|
||||
configureApp(app) {
|
||||
app.provide('msg', 'app-injected')
|
||||
},
|
||||
})
|
||||
customElements.define('my-async-element-with-app', E)
|
||||
|
||||
container.innerHTML = `<my-async-element-with-app></my-async-element-with-app>`
|
||||
const e = container.childNodes[0] as VueElement
|
||||
await new Promise(r => setTimeout(r))
|
||||
expect(e.shadowRoot?.innerHTML).toBe('<div>app-injected</div>')
|
||||
})
|
||||
|
||||
test('with hmr reload', async () => {
|
||||
const __hmrId = '__hmrWithApp'
|
||||
const def = defineComponent({
|
||||
|
|
|
@ -404,9 +404,10 @@ export class VueElement
|
|||
|
||||
const asyncDef = (this._def as ComponentOptions).__asyncLoader
|
||||
if (asyncDef) {
|
||||
this._pendingResolve = asyncDef().then(def =>
|
||||
resolve((this._def = def), true),
|
||||
)
|
||||
this._pendingResolve = asyncDef().then((def: InnerComponentDef) => {
|
||||
def.configureApp = this._def.configureApp
|
||||
resolve((this._def = def), true)
|
||||
})
|
||||
} else {
|
||||
resolve(this._def)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue