diff --git a/ui/src/app/api/messages/batch/route.ts b/ui/src/app/api/messages/batch/route.ts index 4091268f..f47bd0fd 100644 --- a/ui/src/app/api/messages/batch/route.ts +++ b/ui/src/app/api/messages/batch/route.ts @@ -164,11 +164,11 @@ export async function GET(req: Request, res: Response) { }, 100); rl.on("line", (line: string) => { - try { - eventBuffer.push(line); - } catch (error) { - controller.error(error); + if (!line) { + return; } + + eventBuffer.push(line); }); rl.on("close", () => { diff --git a/ui/src/components/Graph/hooks/useStreamMessagesHandler.tsx b/ui/src/components/Graph/hooks/useStreamMessagesHandler.tsx index 463a5dd0..25008de7 100644 --- a/ui/src/components/Graph/hooks/useStreamMessagesHandler.tsx +++ b/ui/src/components/Graph/hooks/useStreamMessagesHandler.tsx @@ -1,6 +1,6 @@ import { useCallback, useMemo, useRef, useState } from "react"; -import { defaultAggregatedData, useGraphContext } from "@/contexts/GraphContext/context"; +import { useGraphContext } from "@/contexts/GraphContext/context"; import { ISimulationAggregatedDataState } from "@/contexts/GraphContext/types"; export const useStreamMessagesHandler = () => { @@ -42,14 +42,6 @@ export const useStreamMessagesHandler = () => { const stopStream = useCallback(() => { eventSource.current?.close(); setStreaming(false); - - dispatch({ - type: "BATCH_UPDATE", - payload: { - currentNode: undefined, - aggregatedData: defaultAggregatedData, - }, - }); }, []); return useMemo( diff --git a/ui/src/components/Graph/modules/Controls.tsx b/ui/src/components/Graph/modules/Controls.tsx index 74e53894..f1820aa5 100644 --- a/ui/src/components/Graph/modules/Controls.tsx +++ b/ui/src/components/Graph/modules/Controls.tsx @@ -1,9 +1,11 @@ import { FC, memo } from "react"; +import { defaultAggregatedData, useGraphContext } from "@/contexts/GraphContext/context"; import { useHandlers } from "../hooks/useHandlers"; import { useStreamMessagesHandler } from "../hooks/useStreamMessagesHandler"; export const Controls: FC = memo(() => { + const { dispatch } = useGraphContext(); const { handleResetSim } = useHandlers(); const { startStream, streaming, stopStream } = useStreamMessagesHandler(); @@ -18,7 +20,16 @@ export const Controls: FC = memo(() => {