@devries-cameron20 / t3code Mirror · read-only / commits / 1c0cc439ff
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 07:00 UTC

fix(web): deleting a thread clears its saved right-panel, diff-panel and mini-player state (#28386)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Victor Vogel committed Nov 1, 2026 at 16:06 UTC 1c0cc439ffba9347dd33f5576b23e958fecf02d8
2 files changed +44 -2
apps/web/src/hooks/useThreadActions.permissions.test.ts
+32
@@ -10,6 +10,11 @@ import * as Cause from "effect/Cause";
10 import { AsyncResult } from "effect/reactivity";
11 import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
12
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 +
18 function deferred<T>() {
19 let resolve!: (value: T) => void;
20 const promise = new Promise<T>((complete) => {
@@ -163,6 +168,23 @@ vi.mock("./useSettings", () => ({
168
169 import { useThreadActions } from "./useThreadActions";
170
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 +
188 const primary = EnvironmentId.make("primary");
189 const secondary = EnvironmentId.make("secondary");
190 const target = { environmentId: secondary, threadId: ThreadId.make("thread") };
@@ -226,6 +248,9 @@ beforeEach(() => {
248 state.toasts = [];
249 state.afterRequest = undefined;
250 state.sessionLookupFails = false;
251 + useRightPanelStore.setState(useRightPanelStore.getInitialState(), true);
252 + useDiffPanelStore.setState(useDiffPanelStore.getInitialState(), true);
253 + usePreviewMiniPlayerStore.setState(usePreviewMiniPlayerStore.getInitialState(), true);
254 });
255
256 describe("thread action permissions", () => {
@@ -284,23 +309,28 @@ describe("thread action permissions", () => {
309
310 it("deletes an archived thread only with its own environment's grant", async () => {
311 state.threads = [];
312 + seedThreadPanelState(target);
313 const actions = useThreadActions();
314 await actions.deleteThread(target);
315 expect(state.requests).toEqual([]);
316 + expect(threadPanelStatePresence(target)).toEqual(panelStateKept);
317 state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
318 expect((await actions.deleteThread(target))._tag).toBe("Success");
319 expect(state.requests).toEqual([
320 expect.objectContaining({ action: "delete", environmentId: secondary }),
321 ]);
322 + expect(threadPanelStatePresence(target)).toEqual(panelStateCleared);
323 });
324
325 it("stops before delete and local cleanup when permission is revoked during session stop", async () => {
326 state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
327 state.threads[0]!.session = { status: "ready" };
328 state.afterRequest = () => state.scopes.get(secondary)!.clear();
329 + seedThreadPanelState(target);
330 expect((await useThreadActions().deleteThread(target))._tag).toBe("Failure");
331 expect(state.requests.map((request) => request.action)).toEqual(["stopSession"]);
332 expect(state.localEffects).toEqual([]);
333 + expect(threadPanelStatePresence(target)).toEqual(panelStateKept);
334 });
335
336 it.each([
@@ -310,10 +340,12 @@ describe("thread action permissions", () => {
340 state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
341 state.threads[0]!.worktreePath = "/worktrees/thread";
342 state.sessionLookupFails = sessionLookupFails;
343 + seedThreadPanelState(target);
344 expect((await useThreadActions().deleteThread(target))._tag).toBe("Success");
345 expect(state.confirm).not.toHaveBeenCalled();
346 expect(state.requests.map((request) => request.action)).toEqual(["stopSession", "delete"]);
347 expect(state.localEffects).toContain("clear-terminal-ui");
348 + expect(threadPanelStatePresence(target)).toEqual(panelStateCleared);
349 });
350
351 it("does not request worktree removal after its grant is revoked during delete", async () => {
apps/web/src/hooks/useThreadActions.ts
+12 -2
@@ -45,7 +45,10 @@ import {
45 readThreadShells,
46 } from "../state/entities";
47 import { useUiStateStore } from "../uiStateStore";
48 +import { useDiffPanelStore } from "../diffPanelStore";
49 +import { usePreviewMiniPlayerStore } from "../previewMiniPlayerStore";
50 import { clearThreadPreviewState } from "../previewStateStore";
51 +import { useRightPanelStore } from "../rightPanelStore";
52 import { useTerminalUiStateStore } from "../terminalUiStateStore";
53 import { buildThreadRouteParams, resolveThreadRouteRef } from "../threadRoutes";
54 import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
@@ -236,6 +239,13 @@ function expireThreadUndos(target: ScopedThreadRef, kinds: readonly string[]) {
239 for (const kind of kinds) ThreadUndo.invalidate(kind, scopedThreadKey(target));
240 }
241
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 +
249 /** A No project thread that already has its own folder, on a server that can promote it. */
250 export function canTurnThreadIntoProject(threadRef: ScopedThreadRef): boolean {
251 const thread = readThreadShell(threadRef);
@@ -437,7 +447,7 @@ export function useThreadActions() {
447 if (result._tag === "Success") {
448 expireThreadUndos(target, [...LIST_PLACEMENT_UNDO_KINDS, "archive"]);
449 refreshArchivedThreadsForEnvironment(target.environmentId);
440 - clearThreadPreviewState(target);
450 + clearDeletedThreadPanelState(target);
451 }
452 return result;
453 }
@@ -561,7 +571,7 @@ export function useThreadActions() {
571 threadRef,
572 );
573 clearTerminalUiState(threadRef);
564 - clearThreadPreviewState(threadRef);
574 + clearDeletedThreadPanelState(threadRef);
575
576 if (shouldNavigateToFallback) {
577 const fallbackThread = fallbackThreadId