Skip to content

Commit 908af5b

Browse files
committed
Guard chatStore setters against no-op updates
chatLocation and chatVisible are persisted through useUserLocalStorage, so every assignment writes to localStorage and notifies watchers. Guard each setter against same-value writes so repeated calls (e.g. hideChat on every /chatgxy route hit, setActiveChatId on every selection change) don't thrash downstream consumers.
1 parent 02ce871 commit 908af5b

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

client/src/stores/chatStore.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,33 @@ export const useChatStore = defineStore("chatStore", () => {
1616

1717
function showChat(chatId?: string | null) {
1818
if (chatId !== undefined) {
19-
activeChatId.value = chatId;
19+
setActiveChatId(chatId);
20+
}
21+
if (!chatVisible.value) {
22+
chatVisible.value = true;
2023
}
21-
chatVisible.value = true;
2224
}
2325

2426
function hideChat() {
25-
chatVisible.value = false;
27+
if (chatVisible.value) {
28+
chatVisible.value = false;
29+
}
2630
}
2731

2832
function toggleChat() {
2933
chatVisible.value = !chatVisible.value;
3034
}
3135

3236
function setLocation(loc: ChatLocation) {
33-
chatLocation.value = loc;
37+
if (chatLocation.value !== loc) {
38+
chatLocation.value = loc;
39+
}
3440
}
3541

3642
function setActiveChatId(id: string | null) {
37-
activeChatId.value = id;
43+
if (activeChatId.value !== id) {
44+
activeChatId.value = id;
45+
}
3846
}
3947

4048
return {

0 commit comments

Comments
 (0)