Skip to content

Commit

Permalink
fix(custom-elements): should not reflect non-decalred properties set …
Browse files Browse the repository at this point in the history
…before upgrade
  • Loading branch information
yyx990803 committed Nov 11, 2022
1 parent 665f2ae commit 5e50909
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,18 @@ describe('defineCustomElement', () => {
expect(props.dataAge).toBe(5)
},
render() {
return `foo: ${this.foo}`
return h('div', `foo: ${this.foo}`)
}
})
const el = document.createElement('my-el-upgrade') as any
el.foo = 'hello'
el.dataset.age = 5
el.notProp = 1
container.appendChild(el)
customElements.define('my-el-upgrade', E)
expect(el.shadowRoot.innerHTML).toBe(`foo: hello`)
expect(el.shadowRoot.firstChild.innerHTML).toBe(`foo: hello`)
// should not reflect if not declared as a prop
expect(el.hasAttribute('not-prop')).toBe(false)
})

// https://github.com/vuejs/core/issues/6163
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime-dom/src/apiCustomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,12 @@ export class VueElement extends BaseClass {
// check if there are props set pre-upgrade or connect
for (const key of Object.keys(this)) {
if (key[0] !== '_') {
this._setProp(key, this[key as keyof this], true, false)
this._setProp(
key,
this[key as keyof this],
rawKeys.includes(key),
false
)
}
}

Expand Down

0 comments on commit 5e50909

Please sign in to comment.