fix(runtime-dom): fix unnecessary warning when setting coerced dom property value

fix #6616
This commit is contained in:
Evan You 2022-09-27 16:39:15 +08:00
parent fc5bdb36ed
commit b1817fe9ee
2 changed files with 4 additions and 2 deletions

View 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()
})

View 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.`,