Skip to content

Commit c5d90f3

Browse files
iamfaranraheeliftikhar5
authored andcommitted
fix no threads infinite re render
1 parent 05a11e2 commit c5d90f3

File tree

1 file changed

+10
-0
lines changed
  • client/packages/lowcoder/src/comps/comps/chatComp/components/context

1 file changed

+10
-0
lines changed

client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,23 @@ export function ChatProvider({ children, storage }: {
303303
};
304304

305305
const deleteThread = async (threadId: string) => {
306+
// Determine if this is the last remaining thread BEFORE we delete it
307+
const isLastThread = state.threadList.length === 1;
308+
306309
// Update local state first
307310
dispatch({ type: "DELETE_THREAD", threadId });
308311

309312
// Delete from storage
310313
try {
311314
await storage.deleteThread(threadId);
312315
dispatch({ type: "MARK_SAVED" });
316+
// avoid deleting the last thread
317+
// if there are no threads left, create a new one
318+
// avoid infinite re-renders
319+
if (isLastThread) {
320+
const newThreadId = await createThread("New Chat");
321+
setCurrentThread(newThreadId);
322+
}
313323
} catch (error) {
314324
console.error("Failed to delete thread:", error);
315325
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy