]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(custom-elements): ensure props are available before initial render. linusborg/ce-initial-props-4716 4792/head
authorThorsten Luenborg <t.luenborg@googlemail.com>
Wed, 13 Oct 2021 19:31:30 +0000 (21:31 +0200)
committerThorsten Luenborg <t.luenborg@googlemail.com>
Wed, 13 Oct 2021 19:31:30 +0000 (21:31 +0200)
packages/runtime-dom/__tests__/customElement.spec.ts
packages/runtime-dom/src/apiCustomElement.ts

index 60b51de38937f4a79fc50027c6685eb26aa90404..eb9e25e75848d48bb1c00b62806409b4bb623051 100644 (file)
@@ -191,13 +191,21 @@ describe('defineCustomElement', () => {
 
     test('handling properties set before upgrading', () => {
       const E = defineCustomElement({
-        props: ['foo'],
+        props: {
+          foo: String,
+          dataAge: Number
+        },
+        setup(props) {
+          expect(props.foo).toBe('hello')
+          expect(props.dataAge).toBe(5)
+        },
         render() {
           return `foo: ${this.foo}`
         }
       })
       const el = document.createElement('my-el-upgrade') as any
       el.foo = 'hello'
+      el.dataset.age = 5
       container.appendChild(el)
       customElements.define('my-el-upgrade', E)
       expect(el.shadowRoot.innerHTML).toBe(`foo: hello`)
index a532da4c6c7f51cd945ee37ff4ab397cf474a70e..37356c86f26c64734c6e26f3eb876df6374fdb4b 100644 (file)
@@ -233,7 +233,7 @@ export class VueElement extends BaseClass {
       }
       if (numberProps) {
         this._numberProps = numberProps
-        this._update()
+        // this._update()
       }
 
       // check if there are props set pre-upgrade or connect
@@ -258,7 +258,9 @@ export class VueElement extends BaseClass {
 
     const asyncDef = (this._def as ComponentOptions).__asyncLoader
     if (asyncDef) {
-      asyncDef().then(resolve)
+      asyncDef()
+        .then(resolve)
+        .then(() => this._update())
     } else {
       resolve(this._def)
     }