bigskysoftware / intercooler-js

Making AJAX as easy as anchor tags
http://intercoolerjs.org
MIT License
4.78k stars 235 forks source link

Elements with SSE trigger do not get cleaned up when swapped out of the DOM #321

Closed adamstep closed 4 years ago

adamstep commented 4 years ago

I have a page with the following setup:

We noticed that items removed from the document are still being triggered by SSE events. Looking at the source code, it doesn't look like we ever call removeEventListener on the event source for removed elements. This causes unexpected behaviors, not to mention memory leaks.

I can see two possible solutions to the problem:

Let me know your thoughts or preferred approaches before I continue with a fix.

1cg commented 4 years ago

What about adding some code to beforeSwapCleanup that looks for SSE triggers in the outgoing content and closes them?

adamstep commented 4 years ago

@chg20 Using beforeSwapCleanup instead of MutationObserver would work, but I think we still need to store the added event listener on the element to properly remove it. I can try that out and update this issue if I get something working.

1cg commented 4 years ago

sounds good

when are you going to start working on htmx? :)

adamstep commented 4 years ago

I tried it out this weekend actually :)

If this same issue affects htmx, I'm happy to submit a PR on that code too

1cg commented 4 years ago

Please do.

Also, you are an old hypertalk guy, right? Let me know if this interests you at all: https://hyperscript.org/

1cg commented 4 years ago

fixed with https://github.com/bigskysoftware/intercooler-js/pull/322