]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(custom-element): avoid setting attr to null if it is removed (#9012)
authoredison <daiwei521@126.com>
Sat, 16 Mar 2024 08:28:03 +0000 (16:28 +0800)
committerGitHub <noreply@github.com>
Sat, 16 Mar 2024 08:28:03 +0000 (16:28 +0800)
Partially fixes #9006
Fixes #10324

packages/runtime-dom/__tests__/customElement.spec.ts
packages/runtime-dom/src/apiCustomElement.ts

index bb08fb1557effd0228fecca575631bb9fe4fae3b..fb746f72c4a2ac85ebd602b1ef4e1f6d24c0acc4 100644 (file)
@@ -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>')
index 337a3d90f9a1ec14dc17881b9bbeafabfa718172..01ce2bad4644681273a2ba6b51ec4008f05c40b5 100644 (file)
@@ -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)