Skip to content

Commit

Permalink
Fix error when accessing status of empty newChats array
Browse files Browse the repository at this point in the history
  • Loading branch information
fankaiLiu committed Dec 3, 2024
1 parent 0949ade commit 3f4d28c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/semi-ui/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,19 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
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) {
Expand Down

0 comments on commit 3f4d28c

Please sign in to comment.