Skip to content

Commit 6ce9142

Browse files
committed
fix(custom-elements): ensure props are available before initial render.
1 parent 7bb9dd0 commit 6ce9142

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,21 @@ describe('defineCustomElement', () => {
191191

192192
test('handling properties set before upgrading', () => {
193193
const E = defineCustomElement({
194-
props: ['foo'],
194+
props: {
195+
foo: String,
196+
dataAge: Number
197+
},
198+
setup(props) {
199+
expect(props.foo).toBe('hello')
200+
expect(props.dataAge).toBe(5)
201+
},
195202
render() {
196203
return `foo: ${this.foo}`
197204
}
198205
})
199206
const el = document.createElement('my-el-upgrade') as any
200207
el.foo = 'hello'
208+
el.dataset.age = 5
201209
container.appendChild(el)
202210
customElements.define('my-el-upgrade', E)
203211
expect(el.shadowRoot.innerHTML).toBe(`foo: hello`)

packages/runtime-dom/src/apiCustomElement.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class VueElement extends BaseClass {
233233
}
234234
if (numberProps) {
235235
this._numberProps = numberProps
236-
this._update()
236+
// this._update()
237237
}
238238

239239
// check if there are props set pre-upgrade or connect
@@ -258,7 +258,9 @@ export class VueElement extends BaseClass {
258258

259259
const asyncDef = (this._def as ComponentOptions).__asyncLoader
260260
if (asyncDef) {
261-
asyncDef().then(resolve)
261+
asyncDef()
262+
.then(resolve)
263+
.then(() => this._update())
262264
} else {
263265
resolve(this._def)
264266
}

0 commit comments

Comments
 (0)