From 37562702725fc328286b63499422856ac47890d7 Mon Sep 17 00:00:00 2001 From: HcySunYang Date: Fri, 16 Jul 2021 04:32:25 +0800 Subject: [PATCH] fix(runtime-dom): capture errors when setting value for IDL (#3578) fix #3576 --- packages/runtime-dom/__tests__/patchProps.spec.ts | 8 ++++++++ packages/runtime-dom/src/modules/props.ts | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index 88080ff92ab..46cd8dc1e5f 100644 --- a/packages/runtime-dom/__tests__/patchProps.spec.ts +++ b/packages/runtime-dom/__tests__/patchProps.spec.ts @@ -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) + }) }) diff --git a/packages/runtime-dom/src/modules/props.ts b/packages/runtime-dom/src/modules/props.ts index 39e068d7ee6..36bb0c11ea3 100644 --- a/packages/runtime-dom/src/modules/props.ts +++ b/packages/runtime-dom/src/modules/props.ts @@ -52,7 +52,10 @@ export function patchDOMProp( return } else if (type === 'number') { // e.g. - 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 }