Skip to content

Commit

Permalink
fix: [Chat] Fixed an issue where sending a message would result in a …
Browse files Browse the repository at this point in the history
…type error when Chat is []
  • Loading branch information
YyumeiZhang committed Aug 20, 2024
1 parent ac7ee98 commit b730765
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/semi-ui/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
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;
Expand All @@ -212,19 +212,18 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
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) {
Expand Down Expand Up @@ -283,7 +282,7 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
const lastChat = chats.length > 0 && chats[chats.length - 1];
let disableSend = false;
if (lastChat && showStopGenerate) {
const lastChatOnGoing = lastChat.status && [MESSAGE_STATUS.LOADING, MESSAGE_STATUS.INCOMPLETE].includes(lastChat.status);
const lastChatOnGoing = lastChat?.status && [MESSAGE_STATUS.LOADING, MESSAGE_STATUS.INCOMPLETE].includes(lastChat?.status);
disableSend = lastChatOnGoing;
showStopGenerate && (showStopGenerateFlag = lastChatOnGoing);
}
Expand Down

0 comments on commit b730765

Please sign in to comment.