Async webcomponent inside another async webcomponent gives error
Vue version
3.4.21
Link to minimal reproduction
Steps to reproduce
- Create two vue components, like Card and Button
- Make them async loading using
defineAsyncComponent
- Wrap them as a webcomponent using
defineCustomElement
- Define them using customElements.define
- In the template put one inside the other `
- it works - Add another Button outside of the Card, observe the error: Uncaught (in promise): parent._instance is null
What is expected?
Components should be render independent of the existence of other components
What is actually happening?
Error is being thrown Uncaught (in promise): parent._instance is null
System Info
Not relevant, using the SFC Playground gives the same error
Any additional comments?
From my exploration, this can be solved by ensuring the component is loaded before trying to access the parent here. By adding this piece of code here: https://github.com/vuejs/core/blob/main/packages/runtime-dom/src/apiCustomElement.ts#L407
const _def = parent._def as ComponentOptions;
if (_def.__asyncLoader && !_def.__asyncResolved) {
await _def.__asyncLoader();
}