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 <openhands@all-hands.dev>
This commit is contained in:
openhands
2026-01-02 20:01:53 +00:00
parent a96b47e481
commit 0ac2bfde73

View File

@@ -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"] });
},