Skip to content

Commit

Permalink
fix(custom-element): avoid setting attr to null if it is removed (vue…
Browse files Browse the repository at this point in the history
…js#9012)

Partially fixes vuejs#9006
Fixes vuejs#10324
  • Loading branch information
edison1105 authored and lynxlangya committed May 30, 2024
1 parent a807519 commit 550923b
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 550923b

Please sign in to comment.