fix(custom-element): avoid setting attr to null if it is removed (#9012)

Partially fixes #9006
Fixes #10324
This commit is contained in:
edison 2024-03-16 16:28:03 +08:00 committed by GitHub
parent cde47bfa97
commit b49306adff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -139,6 +139,12 @@ describe('defineCustomElement', () => {
expect(e.shadowRoot!.innerHTML).toBe('<div></div><div>two</div>')
expect(e.hasAttribute('foo')).toBe(false)
e.foo = undefined
await nextTick()
expect(e.shadowRoot!.innerHTML).toBe('<div></div><div>two</div>')
expect(e.hasAttribute('foo')).toBe(false)
expect(e.foo).toBe(undefined)
e.bazQux = 'four'
await nextTick()
expect(e.shadowRoot!.innerHTML).toBe('<div></div><div>four</div>')

View File

@ -313,7 +313,7 @@ export class VueElement extends BaseClass {
}
protected _setAttr(key: string) {
let value = this.getAttribute(key)
let value = this.hasAttribute(key) ? this.getAttribute(key) : undefined
const camelKey = camelize(key)
if (this._numberProps && this._numberProps[camelKey]) {
value = toNumber(value)