From 6ee78d2e0ea714c38be3b5bb2461aadeb74d436b Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Wed, 31 Jul 2024 18:36:46 +0200 Subject: [PATCH] General performance improvements for folks using compat (#4459) --- compat/src/render.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/compat/src/render.js b/compat/src/render.js index 62dcef0c7e..f18cbd896b 100644 --- a/compat/src/render.js +++ b/compat/src/render.js @@ -33,7 +33,6 @@ const CAMEL_PROPS = /^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/; const ON_ANI = /^on(Ani|Tra|Tou|BeforeInp|Compo)/; const CAMEL_REPLACE = /[A-Z0-9]/g; - const IS_DOM = typeof document !== 'undefined'; // Input types for which onchange should not be converted to oninput. @@ -135,6 +134,7 @@ function handleDomVNode(vnode) { type = vnode.type, normalizedProps = {}; + let isNonDashedType = type.indexOf('-') === -1; for (let i in props) { let value = props[i]; @@ -164,21 +164,23 @@ function handleDomVNode(vnode) { value = ''; } else if (lowerCased === 'translate' && value === 'no') { value = false; - } else if (lowerCased === 'ondoubleclick') { - i = 'ondblclick'; - } else if ( - lowerCased === 'onchange' && - (type === 'input' || type === 'textarea') && - !onChangeInputType(props.type) - ) { - lowerCased = i = 'oninput'; - } else if (lowerCased === 'onfocus') { - i = 'onfocusin'; - } else if (lowerCased === 'onblur') { - i = 'onfocusout'; - } else if (ON_ANI.test(i)) { - i = lowerCased; - } else if (type.indexOf('-') === -1 && CAMEL_PROPS.test(i)) { + } else if (lowerCased[0] === 'o' && lowerCased[1] === 'n') { + if (lowerCased === 'ondoubleclick') { + i = 'ondblclick'; + } else if ( + lowerCased === 'onchange' && + (type === 'input' || type === 'textarea') && + !onChangeInputType(props.type) + ) { + lowerCased = i = 'oninput'; + } else if (lowerCased === 'onfocus') { + i = 'onfocusin'; + } else if (lowerCased === 'onblur') { + i = 'onfocusout'; + } else if (ON_ANI.test(i)) { + i = lowerCased; + } + } else if (isNonDashedType && CAMEL_PROPS.test(i)) { i = i.replace(CAMEL_REPLACE, '-$&').toLowerCase(); } else if (value === null) { value = undefined;