-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix: Make the SSE extension work properly and adhere to tests #2025
Conversation
Previously `sse-swap` were only processed when `sse-connect` was on the root of what was being swapped in. This is now fixed so that the closest sseEventSource is found and used as the event source
remove the nested if statements as there is no difference in handling between sseURL and LegacySSEUrl.
sse-swap
properly when swapped insse-swap
properly when swapped in
sse-swap
properly when swapped in+ more tests differentiating the implementation of sse-swap and hx-trigger * fix for "is closed after removal with no close and activity"
This should be ready to go now. In a rush I commited the test but not the fix for the test. Test coverage is decent at this point |
Hi! I was looking into related SSE PR and it appears that you got potentially proper fix for the important issue of Since it's a medium-to-large PR, I'll be properly focusing on the review during the following week. In the meantime, I provided some comments about current state of the extension and ideas for fixes in this comment #1764 (comment). Please see if there is something useful here and consider incorporating those proposals in your PR. Thank you for your contribution! |
Just fixed that, thanks for bringing it to my attention.
This made for some interesting reading. I think I came to a similar conclusion that you did with respect to #916/#1764. However, instead of creating a new function I reorganized the if statement to populate it with the closest event source in the dom. I implemented the fix in this way instead of removing the I look forward to your review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, I'm sorry I took this long to leave my response and thank you for taking the time to work on improving SSE extension. Adding tests for the extension is HUGE improvement and will definitely help us with maintaining the extension.
As for the fixes, I many your changes definitely positive, but unfortunately, I also found some cases when the extension still behaves not the way users would expect, which I detailed in the code comments. About, separating code into separate functions vs. keeping changes minimal, I very much respect your approach and will not insist on doing it exactly this way, but I also won't object to it, if you find such changes necessary. But i'm still convinced that having sse-connect
search performed on the entire tree of swapped content is crucial for the extension and this is the first thing that should be fixed.
Best regards, and thank you once again for contributing to htmx!
+ seperate eventSource creation logic and event registering logic + manually create event handling, still confused by how hx-trigger works * `createEventSourceOnElement` now looks for event sources in children * explicitly handle legacy sse handling instead of having extra selectors in `querySelectorOnThisOrChildren` + a few readability changes + add regression check to make sure that sseEventSource is only created on elements with sse-connect or equivalent + add test to make sure that sse-connect in the child of a swapped element is handled
I think I've resolved almost all of your comments that I didn't have questions about in my latest commit.
I've now separated the
Thanks for your diligence and your work on this fantastic library! I look forward to your further comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've reviewed the latest changes, and all seems to be in order. My only nitpick would be to rename registerSSE
into something more explicit, like registerSSEEventHandlers
for example. There is also a lot of some whitespace changes which aren't strictly necessary, but I'm fine with it. Would be great to also get some feedback from @benpate, as for me, I approve this PR
@fhp-mec can you confirm that this change is backwards compatible? (I don't know this code well enough to be sure) |
I'm relatively confident in saying its backwards compatible with 1.9.6, I dropped it into a thing that I had deployed a little while ago and it just worked. I'm not super familiar with the javascript support on ie11 so I tried to copy the syntax used in the rest of htmx and use as many of the existing api endpoints as possible. I'm not however setup to test on ie11, so that's the only danger point I think. |
var event = htmx._("makeEvent")(eventName); | ||
event.data = data; | ||
listener(event); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closing ')' missing -> syntax error
var event = htmx._("makeEvent")(eventName); | ||
event.data = data; | ||
listener(event); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and again closing ')' missing
Description
sse:*
inside of hx-trigger (1)sse-swap
events inside of previously swapped contentPreviously
sse-swap
were only processed whensse-connect
was on the root of what was being swapped in.This is now fixed so that the closest sseEventSource is found and used as the event source.
While fixing this issue I ported the existing sse tests (
attributes/hx-sse.js
) to the sse extension, and while running those realized that the sse extension was not compliant with those tests, the change was one line so I decided to add it and make this a general sse extension fix pull request.In some ways this is similar to the #1764 which seems to be stalled. However, it fixes a few more bugs, adds the missing testing.
Corresponding issues: #2023 #916
(1) I'm calling this a partial fix because actually supporting the full
hx-trigger
functionality for sse might not be possible without a substantial refactor of the trigger functionality in htmx itself. Right now the most basic usage ofhx-trigger
with sse events is supported (i.e.hx-trigger="sse:<event name>"
) however, comma separation of events, etc are not supported and can't really be supported unless there htmx allows new keywords and behavior to be added tohx-trigger
by extensions. Or I copy the entirety of the behavior ofhx-trigger
into the sse extension which seems deeply silly and a real pain for the future maintainability of the sse extension.Testing
I initially used the code in this gist to test this manually as there are no tests for the sse backend that I could find
I then realized that there were test cases in
attributes/hx-sse.js
so I copied those, edited them to work with the sse extension.Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded