Skip to content

Conversation

Stanback
Copy link

@Stanback Stanback commented Apr 3, 2017

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: #7

@developit
Copy link
Owner

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.

@thysultan
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants