From 0ac2bfde73cb71be77adb6eb784ddb473df086db Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 2 Jan 2026 20:01:53 +0000 Subject: [PATCH] fix: cleanup orphaned localStorage entries when conversation is deleted When a conversation is deleted, the localStorage entries for that conversation's UI state (right panel visibility, selected tab, unpinned tabs) were not being cleaned up, leading to accumulation of orphaned data. This adds a cleanup function that removes these localStorage entries in the onSuccess callback of the delete mutation. Fixes: APP-306 Co-authored-by: openhands --- .../src/hooks/mutation/use-delete-conversation.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontend/src/hooks/mutation/use-delete-conversation.ts b/frontend/src/hooks/mutation/use-delete-conversation.ts index e654cd6d7e..534d832e22 100644 --- a/frontend/src/hooks/mutation/use-delete-conversation.ts +++ b/frontend/src/hooks/mutation/use-delete-conversation.ts @@ -1,6 +1,15 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; import ConversationService from "#/api/conversation-service/conversation-service.api"; +const cleanupConversationLocalStorage = (conversationId: string) => { + const keysToRemove = [ + `conversation-right-panel-shown-${conversationId}`, + `conversation-selected-tab-${conversationId}`, + `conversation-unpinned-tabs-${conversationId}`, + ]; + keysToRemove.forEach((key) => localStorage.removeItem(key)); +}; + export const useDeleteConversation = () => { const queryClient = useQueryClient(); @@ -32,6 +41,9 @@ export const useDeleteConversation = () => { ); } }, + onSuccess: (_, variables) => { + cleanupConversationLocalStorage(variables.conversationId); + }, onSettled: () => { queryClient.invalidateQueries({ queryKey: ["user", "conversations"] }); },