From: Evan You Date: Tue, 1 Dec 2020 01:05:02 +0000 (-0500) Subject: refactor(runtime-dom): avoid unnecessary typeof checks during props patching X-Git-Tag: v3.0.4~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5a19bb5320b240bb8a2b47fe9b7d4a9d8dda24e2;p=thirdparty%2Fvuejs%2Fcore.git refactor(runtime-dom): avoid unnecessary typeof checks during props patching --- diff --git a/packages/runtime-dom/src/modules/props.ts b/packages/runtime-dom/src/modules/props.ts index ab7a23a02f..068701642f 100644 --- a/packages/runtime-dom/src/modules/props.ts +++ b/packages/runtime-dom/src/modules/props.ts @@ -24,6 +24,7 @@ export function patchDOMProp( el[key] = value == null ? '' : value return } + if (key === 'value' && el.tagName !== 'PROGRESS') { // store value as _value as well since // non-string values will be stringified. @@ -34,29 +35,36 @@ export function patchDOMProp( } return } - if (value === '' && typeof el[key] === 'boolean') { - // e.g. compiles to { multiple: '' } + el[key] = true + return + } else if (value == null && type === 'string') { + // e.g.
+ el[key] = '' + el.removeAttribute(key) + return + } else if (type === 'number') { + // e.g. + el[key] = 0 + el.removeAttribute(key) + return + } + } + + // some properties perform value validation and throw + try { + el[key] = value + } catch (e) { + if (__DEV__) { + warn( + `Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` + + `value ${value} is invalid.`, + e + ) } } }