Skip to content

Commit

Permalink
Merge pull request #1973 from Jiacheng787/patch-1
Browse files Browse the repository at this point in the history
fix: updating the array using push in zustand does not actually trigger component updates
  • Loading branch information
Yidadaa authored Jun 15, 2023
2 parents ea253e3 + 4dd5bf7 commit 9d1a848
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const useChatStore = create<ChatStore>()(

onNewMessage(message) {
get().updateCurrentSession((session) => {
session.messages = session.messages.concat();
session.lastUpdate = Date.now();
});
get().updateStat(message);
Expand Down Expand Up @@ -273,8 +274,7 @@ export const useChatStore = create<ChatStore>()(

// save user's and bot's message
get().updateCurrentSession((session) => {
session.messages.push(userMessage);
session.messages.push(botMessage);
session.messages = session.messages.concat([userMessage, botMessage]);
});

// make request
Expand All @@ -287,7 +287,9 @@ export const useChatStore = create<ChatStore>()(
if (message) {
botMessage.content = message;
}
set(() => ({}));
get().updateCurrentSession((session) => {
session.messages = session.messages.concat();
});
},
onFinish(message) {
botMessage.streaming = false;
Expand All @@ -299,7 +301,6 @@ export const useChatStore = create<ChatStore>()(
sessionIndex,
botMessage.id ?? messageIndex,
);
set(() => ({}));
},
onError(error) {
const isAborted = error.message.includes("aborted");
Expand All @@ -312,8 +313,9 @@ export const useChatStore = create<ChatStore>()(
botMessage.streaming = false;
userMessage.isError = !isAborted;
botMessage.isError = !isAborted;

set(() => ({}));
get().updateCurrentSession((session) => {
session.messages = session.messages.concat();
});
ChatControllerPool.remove(
sessionIndex,
botMessage.id ?? messageIndex,
Expand Down

0 comments on commit 9d1a848

Please sign in to comment.