From 50074ed56ab277ebac6c0d748c8838e430462667 Mon Sep 17 00:00:00 2001 From: Sebastian Pietschner Date: Thu, 21 Nov 2024 05:00:42 +0000 Subject: [PATCH] remove ws handler --- packages/frontend/src/api/hono.ts | 10 ++++++++-- packages/frontend/src/trpcClient.ts | 15 --------------- 2 files changed, 8 insertions(+), 17 deletions(-) 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}/`,