_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

Append uses innerHTML

Open tomberek opened this issue 3 years ago • 1 comments

When appending data to the DOM it uses innerHTML. This destroys any htmx or DOM related listeners on existing nodes. Example

  on message
        append it to the #stream
        get the last of the #stream's children then
        call htmx.process(it) -- call is required for now, not after next release
    end

If multiple messages are received, the htmx behavior of earlier nodes breaks. Perhaps detect the common case of appending a DOM to a DOM and use appendChild internally.

while this works as expected:

     on message
       make a <tr/>
       put event.data into it
       put it at the end of the #stream
       call htmx.process(it)
      end

tomberek avatar Jan 07 '22 04:01 tomberek

I ran into this as well. It's quite tricky to debug. In my case form elements would get cleared when I append new elements to the DOM. Ofcourse, using "put at the end of" solves that.

But figuring this out is tricky.

tonyalaribe avatar Apr 25 '24 17:04 tonyalaribe

welp, took two years but i fixed it

1cg avatar Dec 13 '24 20:12 1cg

Yay!

tomberek avatar Dec 13 '24 22:12 tomberek