Skip to content

Commit b1817fe

Browse files
committedSep 27, 2022
fix(runtime-dom): fix unnecessary warning when setting coerced dom property value
fix #6616
1 parent fc5bdb3 commit b1817fe

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
 

‎packages/runtime-dom/__tests__/patchProps.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ describe('runtime-dom: props patching', () => {
240240
expect(el.size).toBe(100)
241241
patchProp(el, 'size', 100, null)
242242
expect(el.getAttribute('size')).toBe(null)
243+
expect('Failed setting prop "size" on <input>').not.toHaveBeenWarned()
244+
patchProp(el, 'size', null, 'foobar')
243245
expect('Failed setting prop "size" on <input>').toHaveBeenWarnedLast()
244246
})
245247

‎packages/runtime-dom/src/modules/props.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export function patchDOMProp(
6363
needRemove = true
6464
} else if (type === 'number') {
6565
// e.g. <img :width="null">
66-
// the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
6766
value = 0
6867
needRemove = true
6968
}
@@ -96,7 +95,8 @@ export function patchDOMProp(
9695
try {
9796
el[key] = value
9897
} catch (e: any) {
99-
if (__DEV__) {
98+
// do not warn if value is auto-coerced from nullish values
99+
if (__DEV__ && !needRemove) {
100100
warn(
101101
`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
102102
`value ${value} is invalid.`,

0 commit comments

Comments
 (0)
Please sign in to comment.