domc icon indicating copy to clipboard operation
domc copied to clipboard

cloneNode and Custom Elements

Open trusktr opened this issue 6 years ago • 6 comments

My fear is that using Custom Elements in domc (which uses cloneNode) will result in errors/bugs due to certain things like JS props not being cloned to the new nodes. Thoughts on this?

trusktr avatar Feb 25 '19 01:02 trusktr

Maybe you can add thoughts to this old thread, if you have any: https://github.com/w3c/webcomponents/issues/176

trusktr avatar Feb 25 '19 01:02 trusktr

I'm pretty sure cloneNode only happens on initial instantiation of template instances. So when a template is drawn the first time or an new row is added to list. Given the use of a string templating I'm not sure where JS props would come into the picture. The node is cloned then binding is applied to the clone, and then that clone attached to the DOM. Basically the template being cloned from is abstracted from you , and you'd only ever interface with the clone and it is never cloned again. I'm yet to hit an issue using Custom Elements this way using this cloneNode method as used in DomC.

Mind you the Custom Elements I use do most of their work in the Connected Callback instead of the constructor (historically reasons to support backward compatible polyfills in ES5). Have you seen an example of this being a problem? I'm actually pretty interested as I use this exact same approach in my libraries.

ryansolid avatar Feb 25 '19 02:02 ryansolid

As of now, Domc hasn't been tested with Custom Elements, nor designed with it in mind. I had to think about its support. Sorry for the late response)

Freak613 avatar Mar 04 '19 23:03 Freak613

I should add that lit-html and lighterhtml also use this approach of setting templates and cloning them. Both libraries known to support custom elements. So unless you have found a specific issue I do not imagine there should be any issue with the approach taken here. Not to say Domc might not have other hangups with web components, just that the cloneNode part is fairly ubiquitous.

ryansolid avatar Apr 16 '19 05:04 ryansolid

I just can't state that they are supported or tested, until test them myself. But I don't stop other minds to try and see.

Upd: I'm not saying I'm not going to test it, just don't have time for that right now. I hope will have it in nearest future.

Freak613 avatar Apr 16 '19 06:04 Freak613

i have created tag-html as succesor of lit-html with webcomponents in mind i will adapt domc as additional algo as my framework supports dirrent algos to be modular and flexible i can expect how to handle all that with domc support as my tag-html famework is also string template based but it uses tagged template literals.

it replaces lit-html directives with customElements support

frank-dspeed avatar Jan 10 '20 13:01 frank-dspeed