undom icon indicating copy to clipboard operation
undom copied to clipboard

Handle innerHTML

Open Stanback opened this issue 7 years ago • 2 comments

I believe there are two edge cases when it comes to innerHTML support:

  1. Remove childNodes of an element when setting innerHTML
  2. Clear innerHTML from an element when inserting new children

I think this will support the majority of use-cases. I could probably add tests but wanted to run it by you to make sure this is sensible. I'm also not sure if preact's dom diffing algorithm should be doing something different to clear out recycled nodes. (Update: this is less of an issue for the vast majority of use-cases now that Preact 8.x has removed recycling)

Of course the alternative is adding full support for deserializing innerHTML into child nodes and vice-versa (spec https://www.w3.org/TR/DOM-Parsing/#widl-Element-innerHTML0) but seems like you'd either want to make that an optional plugin or go with jsdom at that point.

This relates to my serialization issue here: https://github.com/developit/undom/issues/7

Stanback avatar Apr 03 '17 18:04 Stanback

ahh - good catch. This can serve as the basis for that plugin. Preact's innerHTML usage is pretty standard, it uses innerHTML='' to wipe as that's fastest.

developit avatar Apr 05 '17 16:04 developit

@developit There's also .textContent = null which should be faster and works like .innerHTML in this use case(remove all children).

thysultan avatar Apr 18 '17 07:04 thysultan