From b49306adff4572d90a42ccd231387f16eb966bbe Mon Sep 17 00:00:00 2001 From: edison Date: Sat, 16 Mar 2024 16:28:03 +0800 Subject: [PATCH] fix(custom-element): avoid setting attr to null if it is removed (#9012) Partially fixes #9006 Fixes #10324 --- packages/runtime-dom/__tests__/customElement.spec.ts | 6 ++++++ packages/runtime-dom/src/apiCustomElement.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/runtime-dom/__tests__/customElement.spec.ts b/packages/runtime-dom/__tests__/customElement.spec.ts index bb08fb1557e..fb746f72c4a 100644 --- a/packages/runtime-dom/__tests__/customElement.spec.ts +++ b/packages/runtime-dom/__tests__/customElement.spec.ts @@ -139,6 +139,12 @@ describe('defineCustomElement', () => { expect(e.shadowRoot!.innerHTML).toBe('
two
') expect(e.hasAttribute('foo')).toBe(false) + e.foo = undefined + await nextTick() + expect(e.shadowRoot!.innerHTML).toBe('
two
') + expect(e.hasAttribute('foo')).toBe(false) + expect(e.foo).toBe(undefined) + e.bazQux = 'four' await nextTick() expect(e.shadowRoot!.innerHTML).toBe('
four
') diff --git a/packages/runtime-dom/src/apiCustomElement.ts b/packages/runtime-dom/src/apiCustomElement.ts index 337a3d90f9a..01ce2bad464 100644 --- a/packages/runtime-dom/src/apiCustomElement.ts +++ b/packages/runtime-dom/src/apiCustomElement.ts @@ -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)