From 946a730880f2df54a7ce20c097fe0448dc80f622 Mon Sep 17 00:00:00 2001 From: daiwei Date: Mon, 21 Aug 2023 16:05:42 +0800 Subject: [PATCH 1/3] fix(custom-element): properly set attr --- packages/runtime-dom/src/apiCustomElement.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime-dom/src/apiCustomElement.ts b/packages/runtime-dom/src/apiCustomElement.ts index 5662b0b535b..3af3f795b8e 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) From e1287fc568aa8bd83ca835da6ec8183de8b19e0b Mon Sep 17 00:00:00 2001 From: daiwei Date: Tue, 22 Aug 2023 09:58:12 +0800 Subject: [PATCH 2/3] test: update test case --- packages/runtime-dom/__tests__/customElement.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/runtime-dom/__tests__/customElement.spec.ts b/packages/runtime-dom/__tests__/customElement.spec.ts index 6ccf02c4fa6..445ba1ebe8f 100644 --- a/packages/runtime-dom/__tests__/customElement.spec.ts +++ b/packages/runtime-dom/__tests__/customElement.spec.ts @@ -134,10 +134,11 @@ describe('defineCustomElement', () => { expect(e.shadowRoot!.innerHTML).toBe('
three
two
') expect(e.getAttribute('foo')).toBe('three') - e.foo = null + 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() From 0180ac5f9963d72e9d1181c0a8a1ef0b813a17ca Mon Sep 17 00:00:00 2001 From: daiwei Date: Tue, 22 Aug 2023 10:36:02 +0800 Subject: [PATCH 3/3] test: update test case --- packages/runtime-dom/__tests__/customElement.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/runtime-dom/__tests__/customElement.spec.ts b/packages/runtime-dom/__tests__/customElement.spec.ts index 445ba1ebe8f..a3f3ceac229 100644 --- a/packages/runtime-dom/__tests__/customElement.spec.ts +++ b/packages/runtime-dom/__tests__/customElement.spec.ts @@ -134,6 +134,11 @@ describe('defineCustomElement', () => { expect(e.shadowRoot!.innerHTML).toBe('
three
two
') expect(e.getAttribute('foo')).toBe('three') + e.foo = null + await nextTick() + expect(e.shadowRoot!.innerHTML).toBe('
two
') + expect(e.hasAttribute('foo')).toBe(false) + e.foo = undefined await nextTick() expect(e.shadowRoot!.innerHTML).toBe('
two
')