From 5a19bb5320b240bb8a2b47fe9b7d4a9d8dda24e2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 30 Nov 2020 20:05:02 -0500 Subject: [PATCH] refactor(runtime-dom): avoid unnecessary typeof checks during props patching --- packages/runtime-dom/src/modules/props.ts | 54 +++++++++++++---------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/packages/runtime-dom/src/modules/props.ts b/packages/runtime-dom/src/modules/props.ts index ab7a23a0..06870164 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 + ) } } }