From 3f4d28c8d461a0fd5720e16f3170e1cec128bd85 Mon Sep 17 00:00:00 2001 From: Fankai Liu Date: Tue, 3 Dec 2024 23:18:43 +0800 Subject: [PATCH] Fix error when accessing status of empty newChats array --- packages/semi-ui/chat/index.tsx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/semi-ui/chat/index.tsx b/packages/semi-ui/chat/index.tsx index 2c43782658..c5879e0f37 100644 --- a/packages/semi-ui/chat/index.tsx +++ b/packages/semi-ui/chat/index.tsx @@ -225,19 +225,19 @@ class Chat extends BaseComponent { const { wheelScroll } = this.state; let shouldScroll = false; if (newChats !== oldChats) { - if (Array.isArray(newChats) && Array.isArray(oldChats)) { - const newLastChat = newChats[newChats.length - 1]; - const oldLastChat = oldChats[oldChats.length - 1]; - if (newChats.length > oldChats.length) { - if (oldChats.length === 0 || newLastChat.id !== oldLastChat.id) { - shouldScroll = true; - } - } else if (newChats.length === oldChats.length && newChats.length && - (newLastChat.status !== 'complete' || newLastChat.status !== oldLastChat.status) - ) { - shouldScroll = true; - } + if (Array.isArray(newChats) && Array.isArray(oldChats)) { + const newLastChat = newChats[newChats.length - 1]; + const oldLastChat = oldChats[oldChats.length - 1]; + if (newChats.length > oldChats.length) { + if (oldChats.length === 0 || newLastChat.id !== oldLastChat.id) { + shouldScroll = true; + } + } else if (newChats.length === oldChats.length && newChats.length > 0) { + if (newLastChat.status !== 'complete' || newLastChat.status !== oldLastChat.status) { + shouldScroll = true; + } } + } } if (newHints !== cacheHints) { if (newHints.length > cacheHints.length) {