Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle innerHTML #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Handle innerHTML #8

wants to merge 1 commit into from

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.

None yet

3 participants