Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 4 additions & 3 deletions packages/runtime-dom/src/apiCustomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down