fix(sse): send plain string body for subsequent SSE events

http-kit's send! after the initial response expects a plain string,
not a full response map with status/headers. Sending a response map
was silently dropped, so SSE clients never received change
notifications after the initial "connected" message.

Verified working: toggling a todo in one tab updates the other tab
within ~30ms via SSE.
This commit is contained in:
Florian Schroedl
2026-04-04 18:34:10 +02:00
parent 7b0b320a76
commit 9c3ecc7038

View File

@@ -66,15 +66,12 @@
(swap! sse-clients update group disj ch)))) (swap! sse-clients update group disj ch))))
(defn- sse-notify! (defn- sse-notify!
"Send an SSE event to all listeners of the given groups." "Send an SSE event to all listeners of the given groups.
After the initial response, http-kit send! takes a plain string body."
[groups] [groups]
(doseq [group groups (doseq [group groups
ch (get @sse-clients group)] ch (get @sse-clients group)]
(http/send! ch {:status 200 (http/send! ch (str "data: " group "\n\n") false)))
:headers {"Content-Type" "text/event-stream"
"Cache-Control" "no-cache"}
:body (str "data: " group "\n\n")}
false))) ;; false = don't close, keep streaming
;; --------------------------------------------------------------------------- ;; ---------------------------------------------------------------------------
;; Handlers ;; Handlers