forked from XiaoMo/ChatGPT-Next-Web
Merge pull request #1973 from Jiacheng787/patch-1
fix: updating the array using push in zustand does not actually trigger component updates
This commit is contained in:
commit
9d1a84858c
@ -227,6 +227,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
|
|
||||||
onNewMessage(message) {
|
onNewMessage(message) {
|
||||||
get().updateCurrentSession((session) => {
|
get().updateCurrentSession((session) => {
|
||||||
|
session.messages = session.messages.concat();
|
||||||
session.lastUpdate = Date.now();
|
session.lastUpdate = Date.now();
|
||||||
});
|
});
|
||||||
get().updateStat(message);
|
get().updateStat(message);
|
||||||
@ -273,8 +274,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
|
|
||||||
// save user's and bot's message
|
// save user's and bot's message
|
||||||
get().updateCurrentSession((session) => {
|
get().updateCurrentSession((session) => {
|
||||||
session.messages.push(userMessage);
|
session.messages = session.messages.concat([userMessage, botMessage]);
|
||||||
session.messages.push(botMessage);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// make request
|
// make request
|
||||||
@ -287,7 +287,9 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
if (message) {
|
if (message) {
|
||||||
botMessage.content = message;
|
botMessage.content = message;
|
||||||
}
|
}
|
||||||
set(() => ({}));
|
get().updateCurrentSession((session) => {
|
||||||
|
session.messages = session.messages.concat();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onFinish(message) {
|
onFinish(message) {
|
||||||
botMessage.streaming = false;
|
botMessage.streaming = false;
|
||||||
@ -299,7 +301,6 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
sessionIndex,
|
sessionIndex,
|
||||||
botMessage.id ?? messageIndex,
|
botMessage.id ?? messageIndex,
|
||||||
);
|
);
|
||||||
set(() => ({}));
|
|
||||||
},
|
},
|
||||||
onError(error) {
|
onError(error) {
|
||||||
const isAborted = error.message.includes("aborted");
|
const isAborted = error.message.includes("aborted");
|
||||||
@ -312,8 +313,9 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
botMessage.streaming = false;
|
botMessage.streaming = false;
|
||||||
userMessage.isError = !isAborted;
|
userMessage.isError = !isAborted;
|
||||||
botMessage.isError = !isAborted;
|
botMessage.isError = !isAborted;
|
||||||
|
get().updateCurrentSession((session) => {
|
||||||
set(() => ({}));
|
session.messages = session.messages.concat();
|
||||||
|
});
|
||||||
ChatControllerPool.remove(
|
ChatControllerPool.remove(
|
||||||
sessionIndex,
|
sessionIndex,
|
||||||
botMessage.id ?? messageIndex,
|
botMessage.id ?? messageIndex,
|
||||||
|
Loading…
Reference in New Issue
Block a user