From 923f0e99b9258ceea4742dbcb5da1def7799669d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B6=85=E7=BA=A7=E8=80=81=E7=99=BD=E5=85=94?= Date: Thu, 4 Sep 2025 11:58:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(ChatWindow):=20=E5=A4=84=E7=90=86=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=86=85=E5=AE=B9=E4=B8=BAnull=E6=88=96undefined?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加对消息内容为null或undefined的检查,防止解析时出错 --- .../pc/ckbox/components/ChatWindow/index.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx index bf97e639..4521f4a7 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx @@ -48,6 +48,9 @@ const ChatWindow: React.FC = ({ if (!prevMsg || prevMsg.id !== msg.id) return false; try { + // 检查msg.content和prevMsg.content是否为null或undefined + if (!msg.content || !prevMsg.content) return false; + const currentContent = typeof msg.content === "string" ? JSON.parse(msg.content) @@ -107,7 +110,14 @@ const ChatWindow: React.FC = ({ }; // 解析消息内容,判断消息类型并返回对应的渲染内容 - const parseMessageContent = (content: string, msg: ChatRecord) => { + const parseMessageContent = ( + content: string | null | undefined, + msg: ChatRecord, + ) => { + // 处理null或undefined的内容 + if (content === null || content === undefined) { + return
消息内容不可用
; + } // 检查是否为表情包 if ( typeof content === "string" && @@ -530,7 +540,7 @@ const ChatWindow: React.FC = ({ }; const renderMessage = (msg: ChatRecord) => { - const isOwn = msg.isSend; + const isOwn = msg?.isSend; return (
= ({ )}
{!isOwn && ( -
{msg.senderName}
+
{msg?.senderName}
)} {parseMessageContent(msg.content, msg)}