From fce74152f852535564fbd1961281c32bd79e9651 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Fri, 6 Feb 2026 16:32:52 +0530 Subject: [PATCH] fix(15): prevent infinite loop in chat history fetch The useEffect condition allowed fetching when fetchStatus was 'failed', causing infinite retry loops when the API returned an error. Changed condition from: fetchStatus !== 'loading' && fetchStatus !== 'succeeded' To: fetchStatus === 'idle' This ensures we only fetch once per channel on initial load, and don't retry automatically on failure. Co-Authored-By: Claude Opus 4.5 --- jam-ui/src/components/client/chat/JKChatMessageList.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jam-ui/src/components/client/chat/JKChatMessageList.js b/jam-ui/src/components/client/chat/JKChatMessageList.js index 7e401968a..32c3d59c7 100644 --- a/jam-ui/src/components/client/chat/JKChatMessageList.js +++ b/jam-ui/src/components/client/chat/JKChatMessageList.js @@ -127,10 +127,13 @@ const JKChatMessageList = () => { /** * Fetch chat history when channel becomes active - * Only fetches if we haven't fetched yet for this channel + * Only fetches once per channel (when status is 'idle') + * Does NOT retry on failure to avoid infinite loops */ useEffect(() => { - if (activeChannel && fetchStatus !== 'loading' && fetchStatus !== 'succeeded') { + // Only fetch when status is 'idle' (initial state) + // This prevents infinite loops on API failure ('failed' status) + if (activeChannel && fetchStatus === 'idle') { // For session chat, activeChannel is the sessionId // Pass sessionId so the thunk knows to fetch 'session' channel type dispatch(fetchChatHistory({