Skip to content

Commit 3756270

Browse files
authored
fix(runtime-dom): capture errors when setting value for IDL (#3578)
fix #3576
1 parent 18911ab commit 3756270

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,12 @@ describe('runtime-dom: props patching', () => {
170170
// see https://github.com/vuejs/vue-next/issues/2766
171171
patchProp(el, 'type', 'text', null)
172172
})
173+
174+
test('input with size', () => {
175+
const el = document.createElement('input')
176+
patchProp(el, 'size', null, 100)
177+
expect(el.size).toBe(100)
178+
patchProp(el, 'size', 100, null)
179+
expect(el.getAttribute('size')).toBe(null)
180+
})
173181
})

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export function patchDOMProp(
5252
return
5353
} else if (type === 'number') {
5454
// e.g. <img :width="null">
55-
el[key] = 0
55+
// the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
56+
try {
57+
el[key] = 0
58+
} catch {}
5659
el.removeAttribute(key)
5760
return
5861
}

0 commit comments

Comments
 (0)