Skip to content

Commit

Permalink
fix(runtime-dom): fix unnecessary warning when setting coerced dom pr…
Browse files Browse the repository at this point in the history
…operty value

fix #6616
  • Loading branch information
yyx990803 committed Sep 27, 2022
1 parent fc5bdb3 commit b1817fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/runtime-dom/__tests__/patchProps.spec.ts
Expand Up @@ -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()
})

Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-dom/src/modules/props.ts
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.`,
Expand Down

0 comments on commit b1817fe

Please sign in to comment.