Skip to content
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

fix(custom-element): handle configure app work with async component #12607

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -1330,6 +1330,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>')
})
})

// #9885
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 @@ -403,9 +403,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
Loading