diff --git a/packages/frontend/src/api/hono.ts b/packages/frontend/src/api/hono.ts index 92531d053..74e021fc2 100644 --- a/packages/frontend/src/api/hono.ts +++ b/packages/frontend/src/api/hono.ts @@ -54,7 +54,7 @@ const app = new OpenAPIHono() description: "Server Sent Events", content: { "text/event-stream": { - schema: z.string(), + schema: z.any(), }, }, }, @@ -62,7 +62,7 @@ const app = new OpenAPIHono() }, }), async (c) => { - return streamSSE(c, async (stream) => { + const sseRes = streamSSE(c, async (stream) => { ee.on("invalidate", (data) => stream.writeSSE({ data: JSON.stringify(data), @@ -70,8 +70,14 @@ const app = new OpenAPIHono() id: ulid(), }), ); + + stream.onAbort(() => { + ee.off("invalidate"); + }); // biome-ignore lint/complexity/noBannedTypes: }) as unknown as TypedResponse<{}, 200, string>; + + return sseRes; }, ) .doc31("/api/docs/openapi.json", { diff --git a/packages/frontend/src/trpcClient.ts b/packages/frontend/src/trpcClient.ts index 7f60ecc95..6d51cdd28 100644 --- a/packages/frontend/src/trpcClient.ts +++ b/packages/frontend/src/trpcClient.ts @@ -52,21 +52,6 @@ export const queryClient = new QueryClient({ }, }, }); -try { - // add websocket listener - const ws = new WebSocket( - `ws${backendUrl.protocol === "https:" ? "s" : ""}://${backendUrl.host}/api/ws`, - ); - - ws.addEventListener("message", (event) => { - const data = JSON.parse(event.data) as QueryKey; - queryClient.invalidateQueries({ - queryKey: data, - }); - }); -} catch (error) { - console.error(error); -} export const appClient = hc( `${backendUrl.protocol}//${backendUrl.host}/`,