Skip to content

Commit 85e2850

Browse files
committed
fix(customElement): handle configure app work with async component
1 parent 21f8d9d commit 85e2850

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
@@ -1330,6 +1330,29 @@ describe('defineCustomElement', () => {
13301330

13311331
expect(e.shadowRoot?.innerHTML).toBe('<div>app-injected</div>')
13321332
})
1333+
1334+
// #12448
1335+
test('work with async component', async () => {
1336+
const AsyncComp = defineAsyncComponent(() => {
1337+
return Promise.resolve({
1338+
render() {
1339+
const msg: string | undefined = inject('msg')
1340+
return h('div', {}, msg)
1341+
},
1342+
} as any)
1343+
})
1344+
const E = defineCustomElement(AsyncComp, {
1345+
configureApp(app) {
1346+
app.provide('msg', 'app-injected')
1347+
},
1348+
})
1349+
customElements.define('my-async-element-with-app', E)
1350+
1351+
container.innerHTML = `<my-async-element-with-app></my-async-element-with-app>`
1352+
const e = container.childNodes[0] as VueElement
1353+
await new Promise(r => setTimeout(r))
1354+
expect(e.shadowRoot?.innerHTML).toBe('<div>app-injected</div>')
1355+
})
13331356
})
13341357

13351358
// #9885

packages/runtime-dom/src/apiCustomElement.ts

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

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

0 commit comments

Comments
 (0)