#Suport for SSE on .astro pages

11 messages · Page 1 of 1 (latest)

sick nexus
#

Hello! I'm trying to implement an HTMX website powered by Astro and was wondering if there's any way to implement SSE (Server Sent Events) on Astro Pages so I can send HTML directly as the event content

ancient moss
sick nexus
#

Hi @ancient moss! Thank you for your answer! I was already exploring your examples but what I noticed is the response content is just an string with the content and no Astro components. In my scenario, this is more complex than a counter, I want to render an entire html element with data, and using template strings feels a little bit awkward. I wish there was a way to use SSE on .astro pages or at least an Astro.render method to combine with your approach.

ancient moss
#

htmx was mentioned even in there

tall widget
#

@ancient moss i checked your example but the issue i have with that is when somebody opens up the stream in a browsertab and closes it. Astro does not seem to close the readable stream properly

#

i saw you had that issue somewhere and basically do manual cleanup from the frontend

ancient moss
#

you're right, I struggled with the stream lifecycle a little, like Emitter.off and .on.
One idea maybe is in case you have sessions, you could combine them with closing the streams, or do it after some inactivity timeout.

tall widget
#

Funny part this is only an issue in the dev environment

#

in production it properly closes the connection