]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): fix width and height prop check condition
authorEvan You <yyx990803@gmail.com>
Thu, 7 Dec 2023 02:07:25 +0000 (10:07 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 7 Dec 2023 02:09:26 +0000 (10:09 +0800)
close #9762

packages/runtime-dom/__tests__/patchProps.spec.ts
packages/runtime-dom/src/patchProp.ts

index 19554b028104bb1ee183798bbac6b1cadaedb4cf..f5542c17d8ccfdac6755e528e0308ad040291e2a 100644 (file)
@@ -300,6 +300,13 @@ describe('runtime-dom: props patching', () => {
     expect(el.getAttribute('width')).toBe('24px')
   })
 
+  // # 9762 should fallthrough to `key in el` logic for non embedded tags
+  test('width and height on custom elements', () => {
+    const el = document.createElement('foobar')
+    patchProp(el, 'width', null, '24px')
+    expect(el.getAttribute('width')).toBe('24px')
+  })
+
   test('translate attribute', () => {
     const el = document.createElement('div')
     patchProp(el, 'translate', null, 'no')
index 6c839045a96f25d88ea98f876b0a157b48687b39..9aab512eecc052369b6dfc6f679da003e53b6dc4 100644 (file)
@@ -113,12 +113,14 @@ function shouldSetAsProp(
   // #8780 the width or height of embedded tags must be set as attribute
   if (key === 'width' || key === 'height') {
     const tag = el.tagName
-    return !(
+    if (
       tag === 'IMG' ||
       tag === 'VIDEO' ||
       tag === 'CANVAS' ||
       tag === 'SOURCE'
-    )
+    ) {
+      return false
+    }
   }
 
   // native onclick with string value, must be set as attribute