|
|
@@ -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;
|
|
|
@@ -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) {
|
|
|
@@ -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);
|
|
|
}
|