From: Evan You Date: Tue, 27 Sep 2022 08:39:15 +0000 (+0800) Subject: fix(runtime-dom): fix unnecessary warning when setting coerced dom property value X-Git-Tag: v3.2.40~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1817fe9eeb66a18f405ada9072149515654a9bd;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-dom): fix unnecessary warning when setting coerced dom property value fix #6616 --- diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index b7ce2302f8..10ef9e289b 100644 --- a/packages/runtime-dom/__tests__/patchProps.spec.ts +++ b/packages/runtime-dom/__tests__/patchProps.spec.ts @@ -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 ').not.toHaveBeenWarned() + patchProp(el, 'size', null, 'foobar') expect('Failed setting prop "size" on ').toHaveBeenWarnedLast() }) diff --git a/packages/runtime-dom/src/modules/props.ts b/packages/runtime-dom/src/modules/props.ts index 591f8caa7d..1c1ad0c16f 100644 --- a/packages/runtime-dom/src/modules/props.ts +++ b/packages/runtime-dom/src/modules/props.ts @@ -63,7 +63,6 @@ export function patchDOMProp( needRemove = true } else if (type === 'number') { // e.g. - // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error value = 0 needRemove = true } @@ -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.`,