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-elements): ensure props are available before initial render (fix #4716)) #4792

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/runtime-dom/__tests__/customElement.spec.ts
Expand Up @@ -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`)
Expand Down
6 changes: 4 additions & 2 deletions packages/runtime-dom/src/apiCustomElement.ts
Expand Up @@ -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
Expand All @@ -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())
Copy link
Member Author

@LinusBorg LinusBorg Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to have the asyncWrapper's props updated before it renders the nested actual component.

Without this, the async Component test case fails now.

} else {
resolve(this._def)
}
Expand Down