Skip to content

Commit 70b8640

Browse files
committed
fix no threads infinite re render
1 parent c2f66db commit 70b8640

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)