File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
client/packages/lowcoder/src/comps/comps/chatComp/components/context Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -303,13 +303,23 @@ export function ChatProvider({ children, storage }: {
303
303
} ;
304
304
305
305
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
+
306
309
// Update local state first
307
310
dispatch ( { type : "DELETE_THREAD" , threadId } ) ;
308
311
309
312
// Delete from storage
310
313
try {
311
314
await storage . deleteThread ( threadId ) ;
312
315
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
+ }
313
323
} catch ( error ) {
314
324
console . error ( "Failed to delete thread:" , error ) ;
315
325
}
You can’t perform that action at this time.
0 commit comments