Skip to content

Commit 9f9441a

Browse files
chore(frontend): prevent loading chat detail again if didn't change the chatId (#180)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Optimized chat behavior so that the conversation refreshes only when a different chat is selected, enhancing performance and user experience. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Sma1lboy <[email protected]>
1 parent b6a735b commit 9f9441a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

frontend/src/components/chat/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ export default function Chat() {
7777

7878
// Effect to initialize chat ID and refresh the chat list based on URL parameters
7979
useEffect(() => {
80-
setChatId(urlParams.get('id') || '');
81-
refetchChats();
82-
}, [urlParams, refetchChats]);
80+
const newChatId = urlParams.get('id') || '';
81+
if (newChatId !== chatId) {
82+
setChatId(newChatId);
83+
refetchChats();
84+
}
85+
}, [urlParams, chatId, refetchChats]);
8386

8487
// Effect to add and remove global event listeners
8588
useEffect(() => {

0 commit comments

Comments
 (0)