Skip to content

Commit

Permalink
fix(runtime-dom): capture errors when setting value for IDL (#3578)
Browse files Browse the repository at this point in the history
fix #3576
  • Loading branch information
HcySunYang authored Jul 15, 2021
1 parent 18911ab commit 3756270
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/runtime-dom/__tests__/patchProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,12 @@ describe('runtime-dom: props patching', () => {
// see https://github.com/vuejs/vue-next/issues/2766
patchProp(el, 'type', 'text', null)
})

test('input with size', () => {
const el = document.createElement('input')
patchProp(el, 'size', null, 100)
expect(el.size).toBe(100)
patchProp(el, 'size', 100, null)
expect(el.getAttribute('size')).toBe(null)
})
})
5 changes: 4 additions & 1 deletion packages/runtime-dom/src/modules/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export function patchDOMProp(
return
} else if (type === 'number') {
// e.g. <img :width="null">
el[key] = 0
// the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
try {
el[key] = 0
} catch {}
el.removeAttribute(key)
return
}
Expand Down

0 comments on commit 3756270

Please sign in to comment.