diff --git a/packages/semi-ui/chat/index.tsx b/packages/semi-ui/chat/index.tsx index 5575be61ae..87e2b2b993 100644 --- a/packages/semi-ui/chat/index.tsx +++ b/packages/semi-ui/chat/index.tsx @@ -191,7 +191,7 @@ class Chat extends BaseComponent { const { chats, hints } = nextProps; const newState = {} as any; if (chats !== prevState.chats) { - newState.chats = chats; + newState.chats = chats ?? []; } if (hints !== prevState.cacheHints) { newState.cacheHints = hints; @@ -212,19 +212,18 @@ class Chat extends BaseComponent { const { wheelScroll } = this.state; let shouldScroll = false; if (newChats !== oldChats) { - const newLastChat = newChats[newChats.length - 1]; - const oldLastChat = oldChats[oldChats.length - 1]; - if (newChats.length > oldChats.length) { - if (newLastChat.id !== oldLastChat.id) { + 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 && + (newLastChat.status !== 'complete' || newLastChat.status !== oldLastChat.status) + ) { shouldScroll = true; } - } else if (newChats.length === oldChats.length && - ( - newLastChat.status !== 'complete' || - newLastChat.status !== oldLastChat.status - ) - ) { - shouldScroll = true; } } if (newHints !== cacheHints) { @@ -283,7 +282,7 @@ class Chat extends BaseComponent { const lastChat = chats.length > 0 && chats[chats.length - 1]; let disableSend = false; if (lastChat && showStopGenerate) { - const lastChatOnGoing = lastChat.status && lastChat.status !== 'complete'; + const lastChatOnGoing = lastChat?.status && lastChat?.status !== 'complete'; disableSend = lastChatOnGoing; showStopGenerate && (showStopGenerateFlag = lastChatOnGoing); }