]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): fix unnecessary warning when setting coerced dom property value
authorEvan You <yyx990803@gmail.com>
Tue, 27 Sep 2022 08:39:15 +0000 (16:39 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 27 Sep 2022 08:39:15 +0000 (16:39 +0800)
fix #6616

packages/runtime-dom/__tests__/patchProps.spec.ts
packages/runtime-dom/src/modules/props.ts

index b7ce2302f80bb2dcbbcde3022eafd17427ab7075..10ef9e289b4e8e2b867e3a247adca6b5161d6850 100644 (file)
@@ -240,6 +240,8 @@ describe('runtime-dom: props patching', () => {
     expect(el.size).toBe(100)
     patchProp(el, 'size', 100, null)
     expect(el.getAttribute('size')).toBe(null)
+    expect('Failed setting prop "size" on <input>').not.toHaveBeenWarned()
+    patchProp(el, 'size', null, 'foobar')
     expect('Failed setting prop "size" on <input>').toHaveBeenWarnedLast()
   })
 
index 591f8caa7d0a745ed550c24b72b542ac8bffbce9..1c1ad0c16f7a072e97ac94618a5d27bda1102d07 100644 (file)
@@ -63,7 +63,6 @@ export function patchDOMProp(
       needRemove = true
     } else if (type === 'number') {
       // e.g. <img :width="null">
-      // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
       value = 0
       needRemove = true
     }
@@ -96,7 +95,8 @@ export function patchDOMProp(
   try {
     el[key] = value
   } catch (e: any) {
-    if (__DEV__) {
+    // do not warn if value is auto-coerced from nullish values
+    if (__DEV__ && !needRemove) {
       warn(
         `Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
           `value ${value} is invalid.`,