WebReflection / hyperHTML

A Fast & Light Virtual DOM Alternative
ISC License
3.07k stars 112 forks source link

Uncaught TypeError: info.setProperty is not a function #293

Closed brunoscopelliti closed 5 years ago

brunoscopelliti commented 5 years ago

Ciao Andrea,

I was reading the source of hyperHTML, trying to understand how it works under the hood. I was surprised by this block of code.

var info = isSVG ? {} : style;
for (var _key in newValue) {
var value = newValue[_key];
var styleValue = typeof value === 'number' && !IS_NON_DIMENSIONAL.test(_key) ? value + 'px' : value;
if (/^--/.test(_key)) info.setProperty(_key, styleValue);else info[_key] = styleValue;
}

https://github.com/WebReflection/hyperHTML/blob/master/index.js#L622-L627

Is there any reason why you don't check isSVG before executing info.setProperty? It's probably an edge case, but it results in a runtime exception in my tests (setProperty is not a function in that case). Do you think this is a bug?

Thank you.

WebReflection commented 5 years ago

Do you think this is a bug?

Yes, thanks for filing, yet I'm not sure how you'd like to set CSS properties in the SVG since, AFAIK, there is a reason I just use an empty object, so it might be ignored by SVGs (but I can't remember, I need to re-check the code).

WebReflection commented 5 years ago

So, this specific bug is fixed, but I am kinda sure CSS properties within SVG nodes might come back with other issues, please let me know if that's the case.

brunoscopelliti commented 5 years ago

It seems to work fine: the css variable seems to be propagated nicely to the svg element... also when the variable value changes the svg is updated correcly. Thanks for the fast fix!