WebReflection / hyperHTML

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

read only attributes crash #283

Closed atirip closed 5 years ago

atirip commented 5 years ago

<input form=foo> will crash with: Cannot assign to read only property 'form' of object <HTMLInputElement>

The reason, likely, is that form attribute is special, always pointing to form the input belongs, even when not set in HTML. The quick and dirty workaround that works for me as of now, was just exclude form from direct access like this:

else if (name === 'data' || !isSVG && (name in node && name != 'form') ) {

and directing setting form attribute with setAttribute()

But I am sure there is more and proper solution, of course, would be to exclude all such attributes.

WebReflection commented 5 years ago

interesting, never used that property myself. By any chance you have an idea which attribute is readonly ? excluding form only doesn't look like a scaling solution, thanks.

atirip commented 5 years ago

I can only guess that all attributes which point to DOM object. For these, in HTML an id of that object must be specified, but accessing the attribute gets not that string id, but a DOM object. Quick test pointed that also 'list' attribute is such.

WebReflection commented 5 years ago

Quick test pointed that also 'list' attribute is such.

uhm ... so aria attributes too, but so far I had no issues in setting those so unless there is a reproducible crash I'll try to keep the list as small as possible.

Does list crash too?

WebReflection commented 5 years ago

P.S. the RegEx is here, in case you'd like to contribute/test/improve it https://github.com/WebReflection/hyperHTML/blob/master/esm/objects/Updates.js#L221

thanks for the report

atirip commented 5 years ago

can confirm, list also crashes with the same error and is probably used more.

Thanks.

WebReflection commented 5 years ago

2.15.2 has both in, please let me know if you find others, thanks.