#Suport for SSE on .astro pages
11 messages · Page 1 of 1 (latest)
I happen to have an example with Server Sent Events https://github.com/MicroWebStacks/astro-examples/tree/main#03_sse-counter here the response details https://github.com/MicroWebStacks/astro-examples/blob/5b5c6e317b13d82789c2230d62dd2431def4631c/03_sse-counter/src/pages/api/stream.js#L25
So to say, SSE can be used like in any other and nothing specific to Astro in there.
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.
Hmm, now I see, thanks for the clarification. I don't have a specific answer, but that might have to be combined with something like this https://github.com/withastro/roadmap/discussions/615
htmx was mentioned even in there
@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
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.