Skip to content

Commit 5ba1afb

Browse files
authored
fix(custom-element): ensure configureApp is applied to async component (#12607)
close #12448
1 parent 73055d8 commit 5ba1afb

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

packages/runtime-dom/__tests__/customElement.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,29 @@ describe('defineCustomElement', () => {
15661566
expect(e.shadowRoot?.innerHTML).toBe('<div>app-injected</div>')
15671567
})
15681568

1569+
// #12448
1570+
test('work with async component', async () => {
1571+
const AsyncComp = defineAsyncComponent(() => {
1572+
return Promise.resolve({
1573+
render() {
1574+
const msg: string | undefined = inject('msg')
1575+
return h('div', {}, msg)
1576+
},
1577+
} as any)
1578+
})
1579+
const E = defineCustomElement(AsyncComp, {
1580+
configureApp(app) {
1581+
app.provide('msg', 'app-injected')
1582+
},
1583+
})
1584+
customElements.define('my-async-element-with-app', E)
1585+
1586+
container.innerHTML = `<my-async-element-with-app></my-async-element-with-app>`
1587+
const e = container.childNodes[0] as VueElement
1588+
await new Promise(r => setTimeout(r))
1589+
expect(e.shadowRoot?.innerHTML).toBe('<div>app-injected</div>')
1590+
})
1591+
15691592
test('with hmr reload', async () => {
15701593
const __hmrId = '__hmrWithApp'
15711594
const def = defineComponent({

packages/runtime-dom/src/apiCustomElement.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,10 @@ export class VueElement
404404

405405
const asyncDef = (this._def as ComponentOptions).__asyncLoader
406406
if (asyncDef) {
407-
this._pendingResolve = asyncDef().then(def =>
408-
resolve((this._def = def), true),
409-
)
407+
this._pendingResolve = asyncDef().then((def: InnerComponentDef) => {
408+
def.configureApp = this._def.configureApp
409+
resolve((this._def = def), true)
410+
})
410411
} else {
411412
resolve(this._def)
412413
}

0 commit comments

Comments
 (0)