Skip to content

Commit

Permalink
fix(custom-element): avoid setting attr to null if it is removed (#9012)
Browse files Browse the repository at this point in the history
Partially fixes #9006
Fixes #10324
  • Loading branch information
edison1105 committed Mar 16, 2024
1 parent cde47bf commit b49306a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Expand Up @@ -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>')
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/apiCustomElement.ts
Expand Up @@ -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)
Expand Down

0 comments on commit b49306a

Please sign in to comment.