Skip to content

Commit b49306a

Browse files
authoredMar 16, 2024··
fix(custom-element): avoid setting attr to null if it is removed (#9012)
Partially fixes #9006 Fixes #10324
1 parent cde47bf commit b49306a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
 

‎packages/runtime-dom/__tests__/customElement.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ describe('defineCustomElement', () => {
139139
expect(e.shadowRoot!.innerHTML).toBe('<div></div><div>two</div>')
140140
expect(e.hasAttribute('foo')).toBe(false)
141141

142+
e.foo = undefined
143+
await nextTick()
144+
expect(e.shadowRoot!.innerHTML).toBe('<div></div><div>two</div>')
145+
expect(e.hasAttribute('foo')).toBe(false)
146+
expect(e.foo).toBe(undefined)
147+
142148
e.bazQux = 'four'
143149
await nextTick()
144150
expect(e.shadowRoot!.innerHTML).toBe('<div></div><div>four</div>')

‎packages/runtime-dom/src/apiCustomElement.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export class VueElement extends BaseClass {
313313
}
314314

315315
protected _setAttr(key: string) {
316-
let value = this.getAttribute(key)
316+
let value = this.hasAttribute(key) ? this.getAttribute(key) : undefined
317317
const camelKey = camelize(key)
318318
if (this._numberProps && this._numberProps[camelKey]) {
319319
value = toNumber(value)

0 commit comments

Comments
 (0)
Please sign in to comment.