From f6cbd251509e0a6c957ff16695d62d151743af8c Mon Sep 17 00:00:00 2001 From: Ryan Hopper-Lowe <46546486+ryanhopperlowe@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:49:08 -0600 Subject: [PATCH] fix: prevent event source from reconnecting after SSE close event (#726) --- ui/admin/app/components/chat/ChatContext.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/admin/app/components/chat/ChatContext.tsx b/ui/admin/app/components/chat/ChatContext.tsx index 0c3e0b332..f43ad5208 100644 --- a/ui/admin/app/components/chat/ChatContext.tsx +++ b/ui/admin/app/components/chat/ChatContext.tsx @@ -181,11 +181,12 @@ function useMessageSource(threadId?: Nullish) { if (!threadId) return; - const source = ThreadsService.getThreadEventSource(threadId); - let replayComplete = false; let replayMessages: ChatEvent[] = []; + const source = ThreadsService.getThreadEventSource(threadId); + source.addEventListener("close", source.close); + source.onmessage = (chunk) => { const event = JSON.parse(chunk.data) as ChatEvent;