]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(custom-element): ensure configureApp is applied to async component (#12607)
authoredison <daiwei521@126.com>
Thu, 5 Jun 2025 02:10:52 +0000 (10:10 +0800)
committerGitHub <noreply@github.com>
Thu, 5 Jun 2025 02:10:52 +0000 (10:10 +0800)
close #12448

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

index a2b4c263699c38274ab6b7934187ed62f593f583..c44840df5e31d8b38baa6c75c577c1d92b1d233a 100644 (file)
@@ -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({
index 56b86a5fd9e0cea6803cbbafc8050c06f1c933c9..edf7c4313534d02d2ec09de6ffbd7cb35ddf72f9 100644 (file)
@@ -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)
     }