Closed adamstep closed 4 years ago
What about adding some code to beforeSwapCleanup
that looks for SSE triggers in the outgoing content and closes them?
@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.
sounds good
when are you going to start working on htmx? :)
I tried it out this weekend actually :)
If this same issue affects htmx, I'm happy to submit a PR on that code too
Please do.
Also, you are an old hypertalk guy, right? Let me know if this interests you at all: https://hyperscript.org/
I have a page with the following setup:
ic-sse-src
attribute on the body tagic-trigger-on="sse:event"
attribute.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:
sourceElement
is still part of the document. If not, remove the event listener from the source at that time. This lazy cleanup would ensure correctness, but it wouldn't prevent memory leaksLet me know your thoughts or preferred approaches before I continue with a fix.