Skip to content

Commit 0b2b7e1

Browse files
saphidclaude
authored andcommitted
fix(web): deleting a thread clears its side chats' drafts
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c3cfb5e commit 0b2b7e1

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎apps/web/src/components/chat/SideChatPane.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import {
1414
import { Trash2Icon, XIcon } from "lucide-react";
1515
import { useEffect, useState } from "react";
1616

17+
import { useComposerDraftStore } from "../../composerDraftStore";
1718
import { ComposerHandleContext } from "../../composerHandleContext";
1819
import { useClientSettings } from "../../hooks/useSettings";
20+
import { releaseComposerDraftUploads } from "../../lib/composerDraftUploads";
1921
import type { SideChatParentPanel } from "../../lib/sideChatPane";
2022
import { readLocalApi } from "../../localApi";
2123
import { hostRightPanel, useRightPanelStore } from "../../rightPanelStore";
@@ -111,6 +113,8 @@ export default function SideChatPane(props: {
111113
});
112114
setDeleting(false);
113115
if (result._tag === "Success") {
116+
releaseComposerDraftUploads(threadRef);
117+
useComposerDraftStore.getState().clearDraftThread(threadRef);
114118
useRightPanelStore.getState().closeSurface(parentRef, `side-chat:${threadId}`);
115119
} else if (!isAtomCommandInterrupted(result)) {
116120
const error = squashAtomCommandFailure(result);

‎apps/web/src/hooks/useThreadActions.permissions.test.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const state = vi.hoisted(() => ({
3131
projectId: ProjectId;
3232
title: string;
3333
worktreePath: string | null;
34+
lineage: { parentThreadId: ThreadId | null; sideChat?: boolean };
3435
session: { status: "ready" | "stopped" } | null;
3536
latestTurn: null;
3637
}[],
@@ -119,7 +120,8 @@ vi.mock("../components/Sidebar.logic", () => ({
119120
vi.mock("../composerDraftStore", () => ({
120121
useComposerDraftStore: (select: (store: unknown) => unknown) =>
121122
select({
122-
clearDraftThread: () => state.localEffects.push("clear-draft"),
123+
clearDraftThread: (ref: ScopedThreadRef) =>
124+
state.localEffects.push(`clear-draft:${ref.threadId}`),
123125
clearProjectDraftThreadById: () => state.localEffects.push("clear-project-draft"),
124126
}),
125127
}));
@@ -139,7 +141,8 @@ vi.mock("../lib/archivedThreadsState", () => ({
139141
refreshArchivedThreadsForEnvironment: () => state.localEffects.push("refresh-archive"),
140142
}));
141143
vi.mock("../lib/composerDraftUploads", () => ({
142-
releaseComposerDraftUploads: () => state.localEffects.push("release-uploads"),
144+
releaseComposerDraftUploads: (ref: ScopedThreadRef) =>
145+
state.localEffects.push(`release-uploads:${ref.threadId}`),
143146
}));
144147
vi.mock("../localApi", () => ({
145148
readLocalApi: () => ({ dialogs: { confirm: state.confirm } }),
@@ -238,6 +241,7 @@ beforeEach(() => {
238241
projectId: ProjectId.make("project"),
239242
title: "Thread",
240243
worktreePath: null,
244+
lineage: { parentThreadId: null },
241245
session: null,
242246
latestTurn: null,
243247
},
@@ -348,6 +352,24 @@ describe("thread action permissions", () => {
348352
expect(threadPanelStatePresence(target)).toEqual(panelStateCleared);
349353
});
350354

355+
it("clears the drafts of the side chats deleted with it", async () => {
356+
state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
357+
const parent = state.threads[0]!;
358+
state.threads.push(
359+
{
360+
...parent,
361+
id: ThreadId.make("side-chat"),
362+
lineage: { parentThreadId: parent.id, sideChat: true },
363+
},
364+
{ ...parent, id: ThreadId.make("fork"), lineage: { parentThreadId: parent.id } },
365+
);
366+
expect((await useThreadActions().deleteThread(target))._tag).toBe("Success");
367+
expect(state.localEffects).toEqual(
368+
expect.arrayContaining(["release-uploads:side-chat", "clear-draft:side-chat"]),
369+
);
370+
expect(state.localEffects).not.toContain("clear-draft:fork");
371+
});
372+
351373
it("does not request worktree removal after its grant is revoked during delete", async () => {
352374
state.scopes
353375
.get(secondary)!

‎apps/web/src/hooks/useThreadActions.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,15 @@ export function useThreadActions() {
566566
refreshArchivedThreadsForEnvironment(threadRef.environmentId);
567567
releaseComposerDraftUploads(threadRef);
568568
clearComposerDraftForThread(threadRef);
569+
// The server deletes the thread's side chats with it.
570+
for (const entry of threads) {
571+
if (entry.lineage.sideChat !== true || entry.lineage.parentThreadId !== threadRef.threadId) {
572+
continue;
573+
}
574+
const sideChatRef = scopeThreadRef(threadRef.environmentId, entry.id);
575+
releaseComposerDraftUploads(sideChatRef);
576+
clearComposerDraftForThread(sideChatRef);
577+
}
569578
clearProjectDraftThreadById(
570579
scopeProjectRef(threadRef.environmentId, thread.projectId),
571580
threadRef,

0 commit comments

Comments
 (0)