fix(custom-element): ensure configureApp is applied to async component (#12607)

close #12448
This commit is contained in:
edison 2025-06-05 10:10:52 +08:00 committed by GitHub
parent 73055d8d95
commit 5ba1afba09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 3 deletions

View File

@ -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({

View File

@ -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)
}