From cf6c747fab053312cfe0d8dd013d0c61231187a3 Mon Sep 17 00:00:00 2001 From: JYC0413 Date: Tue, 16 Jan 2024 17:10:26 +0800 Subject: [PATCH] fix bug --- components/Chat/Chat.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index 07ddd8d..8dbac1b 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -150,7 +150,8 @@ export const Chat = memo(({stopConversationRef}: Props) => { let chunkValue = decoder.decode(value); const regex = /}(?={)/g; const parts = chunkValue.split(regex); - const objects = parts.map(part => { + let objects: any[] = [] + parts.forEach(part => { part = part.trim(); if (!part.startsWith('{')) { part = '{' + part; @@ -158,7 +159,11 @@ export const Chat = memo(({stopConversationRef}: Props) => { if (!part.endsWith('}')) { part = part + '}'; } - return JSON.parse(part); + try { + objects.push(JSON.parse(part)); + }catch (e) { + console.log("error JSON",part); + } }); objects.forEach(obj => {