Skip to content

Commit f043fb6

Browse files
only21milclaude
andcommitted
fix(web): deleting a thread clears its saved right-panel, diff-panel and mini-player state
The three stores' removeThread actions had no callers, so a thread deleted from this client left its right-panel and diff-panel entries (both persisted to localStorage) and its mini-player entry behind. Thread delete now calls them next to the existing preview cleanup, for live and archived threads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 54c5f25 commit f043fb6

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import * as Cause from "effect/Cause";
1010
import { AsyncResult } from "effect/reactivity";
1111
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
1212

13+
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
14+
import { useDiffPanelStore } from "../diffPanelStore";
15+
import { browserMiniPlayerSource, usePreviewMiniPlayerStore } from "../previewMiniPlayerStore";
16+
import { useRightPanelStore } from "../rightPanelStore";
17+
1318
function deferred<T>() {
1419
let resolve!: (value: T) => void;
1520
const promise = new Promise<T>((complete) => {
@@ -163,6 +168,23 @@ vi.mock("./useSettings", () => ({
163168

164169
import { useThreadActions } from "./useThreadActions";
165170

171+
function seedThreadPanelState(ref: ScopedThreadRef) {
172+
useRightPanelStore.getState().show(ref);
173+
useDiffPanelStore.getState().selectGitScope(ref, "branch");
174+
usePreviewMiniPlayerStore.getState().open(ref, browserMiniPlayerSource("tab"));
175+
}
176+
177+
function threadPanelStatePresence(ref: ScopedThreadRef) {
178+
const key = scopedThreadKey(ref);
179+
return {
180+
rightPanel: key in useRightPanelStore.getState().byThreadKey,
181+
diffPanel: key in useDiffPanelStore.getState().byThreadKey,
182+
miniPlayer: key in usePreviewMiniPlayerStore.getState().byThreadKey,
183+
};
184+
}
185+
const panelStateKept = { rightPanel: true, diffPanel: true, miniPlayer: true };
186+
const panelStateCleared = { rightPanel: false, diffPanel: false, miniPlayer: false };
187+
166188
const primary = EnvironmentId.make("primary");
167189
const secondary = EnvironmentId.make("secondary");
168190
const target = { environmentId: secondary, threadId: ThreadId.make("thread") };
@@ -226,6 +248,9 @@ beforeEach(() => {
226248
state.toasts = [];
227249
state.afterRequest = undefined;
228250
state.sessionLookupFails = false;
251+
useRightPanelStore.setState(useRightPanelStore.getInitialState(), true);
252+
useDiffPanelStore.setState(useDiffPanelStore.getInitialState(), true);
253+
usePreviewMiniPlayerStore.setState(usePreviewMiniPlayerStore.getInitialState(), true);
229254
});
230255

231256
describe("thread action permissions", () => {
@@ -284,23 +309,28 @@ describe("thread action permissions", () => {
284309

285310
it("deletes an archived thread only with its own environment's grant", async () => {
286311
state.threads = [];
312+
seedThreadPanelState(target);
287313
const actions = useThreadActions();
288314
await actions.deleteThread(target);
289315
expect(state.requests).toEqual([]);
316+
expect(threadPanelStatePresence(target)).toEqual(panelStateKept);
290317
state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
291318
expect((await actions.deleteThread(target))._tag).toBe("Success");
292319
expect(state.requests).toEqual([
293320
expect.objectContaining({ action: "delete", environmentId: secondary }),
294321
]);
322+
expect(threadPanelStatePresence(target)).toEqual(panelStateCleared);
295323
});
296324

297325
it("stops before delete and local cleanup when permission is revoked during session stop", async () => {
298326
state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
299327
state.threads[0]!.session = { status: "ready" };
300328
state.afterRequest = () => state.scopes.get(secondary)!.clear();
329+
seedThreadPanelState(target);
301330
expect((await useThreadActions().deleteThread(target))._tag).toBe("Failure");
302331
expect(state.requests.map((request) => request.action)).toEqual(["stopSession"]);
303332
expect(state.localEffects).toEqual([]);
333+
expect(threadPanelStatePresence(target)).toEqual(panelStateKept);
304334
});
305335

306336
it.each([
@@ -310,10 +340,12 @@ describe("thread action permissions", () => {
310340
state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
311341
state.threads[0]!.worktreePath = "/worktrees/thread";
312342
state.sessionLookupFails = sessionLookupFails;
343+
seedThreadPanelState(target);
313344
expect((await useThreadActions().deleteThread(target))._tag).toBe("Success");
314345
expect(state.confirm).not.toHaveBeenCalled();
315346
expect(state.requests.map((request) => request.action)).toEqual(["stopSession", "delete"]);
316347
expect(state.localEffects).toContain("clear-terminal-ui");
348+
expect(threadPanelStatePresence(target)).toEqual(panelStateCleared);
317349
});
318350

319351
it("does not request worktree removal after its grant is revoked during delete", async () => {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ import {
4545
readThreadShells,
4646
} from "../state/entities";
4747
import { useUiStateStore } from "../uiStateStore";
48+
import { useDiffPanelStore } from "../diffPanelStore";
49+
import { usePreviewMiniPlayerStore } from "../previewMiniPlayerStore";
4850
import { clearThreadPreviewState } from "../previewStateStore";
51+
import { useRightPanelStore } from "../rightPanelStore";
4952
import { useTerminalUiStateStore } from "../terminalUiStateStore";
5053
import { buildThreadRouteParams, resolveThreadRouteRef } from "../threadRoutes";
5154
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
@@ -236,6 +239,13 @@ function expireThreadUndos(target: ScopedThreadRef, kinds: readonly string[]) {
236239
for (const kind of kinds) ThreadUndo.invalidate(kind, scopedThreadKey(target));
237240
}
238241

242+
function clearDeletedThreadPanelState(ref: ScopedThreadRef) {
243+
clearThreadPreviewState(ref);
244+
useRightPanelStore.getState().removeThread(ref);
245+
useDiffPanelStore.getState().removeThread(ref);
246+
usePreviewMiniPlayerStore.getState().removeThread(ref);
247+
}
248+
239249
/** A No project thread that already has its own folder, on a server that can promote it. */
240250
export function canTurnThreadIntoProject(threadRef: ScopedThreadRef): boolean {
241251
const thread = readThreadShell(threadRef);
@@ -437,7 +447,7 @@ export function useThreadActions() {
437447
if (result._tag === "Success") {
438448
expireThreadUndos(target, [...LIST_PLACEMENT_UNDO_KINDS, "archive"]);
439449
refreshArchivedThreadsForEnvironment(target.environmentId);
440-
clearThreadPreviewState(target);
450+
clearDeletedThreadPanelState(target);
441451
}
442452
return result;
443453
}
@@ -561,7 +571,7 @@ export function useThreadActions() {
561571
threadRef,
562572
);
563573
clearTerminalUiState(threadRef);
564-
clearThreadPreviewState(threadRef);
574+
clearDeletedThreadPanelState(threadRef);
565575

566576
if (shouldNavigateToFallback) {
567577
const fallbackThread = fallbackThreadId

0 commit comments

Comments
 (0)