-
Notifications
You must be signed in to change notification settings - Fork 14
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
SSE Closing Event Loop #4
Comments
Hello,
My backend is written in php and is very simple (for anyone curious, here it is)
I base my frontend on the official updated documentation of the sse extension (the one update since a month ago). The Said "error": Thank you for any help provided ! |
@GrimalDev check the EventStream messages in Chrome's network tab for the SSE call. Two things: you probably need a tiny sleep after the close message to ensure it is actually delivered before the connection is closed; and you might need an empty data value along with the close event (I seem to recall this but I'm not really sure). |
First, thank you for answering. I have linked you a screenshot of the networks tab in action, the sse request ends correctly from chromes point of view (I still added a little cooldown). If I open the sse endpoint in an empty tab for exemple, the request ends and never fires again. But as you can see on the screenshot, the the request is fired again from htmx's point of point. My theory is that the automatic backoff system sees an error and thinks the sse request hasn't been ended properly, thus provoking a new request. |
@GrimalDev I'm sorry, I should have looked a little closer at your import. The close function missed version 2.0.0, apparently. Try https://unpkg.com/htmx-ext-sse@2.1.0/sse.js |
WELL WELL, that is a nice point ! Thank you A LOT |
Not sure if there is a preferred way to raise questions/ideas here, apologies ahead of time.
I am wondering if there is a blessed way to close a SSE event loop. Thinking of a general case where you are checking on a job status and once complete, the server closing the connection. Closing the connection will just cause the client to restablish the request. When using HTMX one possible option is to do an hx-swap-oob to replace the element that create the SSE, cleanup fails here though and some exceptions are raised within HTMX on cleanup.
Happy to contribute but was unsure what the maintainers thought in this case.
The text was updated successfully, but these errors were encountered: