From f1c29ff9e219c46a768bc46b22553bb8a436e6c1 Mon Sep 17 00:00:00 2001 From: Abdurrahman Rajab Date: Fri, 12 Jan 2024 09:59:22 +0300 Subject: [PATCH] fix: chunk processing in Chat component (#289) * fix: chunk processing in Chat component. * chore: format and lint the code --- src/repo-query/pages/chat.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/repo-query/pages/chat.tsx b/src/repo-query/pages/chat.tsx index 2b40cd5c..7717bc45 100644 --- a/src/repo-query/pages/chat.tsx +++ b/src/repo-query/pages/chat.tsx @@ -18,7 +18,8 @@ export const Chat = ({ ownerName, repoName }: { ownerName: string, repoName: str const processChunk = (chunk: string) => { const chunkLines = chunk.split("\n"); - const [eventLine, dataLine] = chunkLines; + const indexOfEvent = chunkLines.findIndex(e => e.includes("event: ")); + const [eventLine, dataLine] = [chunkLines[indexOfEvent], chunkLines[indexOfEvent + 1]]; const event = eventLine.split(": ")[1]; let data:any; @@ -26,7 +27,7 @@ export const Chat = ({ ownerName, repoName }: { ownerName: string, repoName: str try { data = JSON.parse(dataLine.split(": ")[1]); } catch (e) { - console.error(dataLine); + console.error("The recieved data line", dataLine); // remove quotes from string data = dataLine.split("data: ")[1].substring(1, dataLine.split("data: ")[1].length - 2);