@devries-cameron20 / t3code-1 / commits / 10f88f34ed
Fork 0

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

fix(web): restore folder breadcrumb trails when reopening tabs (#30706)

Johan Vaz committed Nov 6, 2026 at 12:38 UTC 10f88f34edca46ee529db09598476715f32d507b
2 files changed +139 -23
apps/web/src/reopenClosedView.test.ts
+120 -22
@@ -12,6 +12,7 @@ import { __setClientSettingsForTests } from "./hooks/useSettings";
12 import { readThreadPreviewState, resetPreviewStateForTests } from "./previewStateStore";
13 import { planNextReopen, type ReopenOwnerState, reopenClosedView } from "./reopenClosedView";
14 import {
15 + hostRightPanel,
16 selectThreadRightPanelState,
17 type ThreadRightPanelState,
18 useRightPanelStore,
@@ -40,28 +41,117 @@ beforeEach(() => {
41 });
42
43 describe("reopenClosedView", () => {
43 - it("restores a file tab at its line without creating a browser session", async () => {
44 - const openPreview = vi.fn();
45 - const reopened = await reopenClosedView(
46 - {
47 - kind: "panel-tab",
44 + it.each([
45 + { relativePath: "src/app.ts", line: 18, folderTrail: undefined },
46 + { relativePath: "apps", line: null, folderTrail: "apps/web/src" },
47 + { relativePath: "", line: null, folderTrail: "apps/web/src" },
48 + ])(
49 + "restores the captured file or folder tab at '$relativePath'",
50 + async ({ relativePath, line, folderTrail }) => {
51 + const panels = useRightPanelStore.getState();
52 + if (folderTrail === undefined) panels.openFile(threadRef, relativePath, line ?? undefined);
53 + else {
54 + panels.openFile(threadRef, folderTrail);
55 + panels.navigateFolder(threadRef, `file:${folderTrail}`, relativePath, folderTrail);
56 + }
57 + const expected =
58 + relativePath === ""
59 + ? { kind: "files", id: "files", folderTrail }
60 + : {
61 + kind: "file",
62 + id: `file:${relativePath}`,
63 + relativePath,
64 + revealLine: line,
65 + revealRequestId: 1,
66 + ...(folderTrail === undefined ? {} : { folderTrail }),
67 + };
68 + const before = selectThreadRightPanelState(
69 + useRightPanelStore.getState().byThreadKey,
70 threadRef,
49 - surface: {
50 - kind: "file",
51 - id: "file:src/app.ts",
52 - relativePath: "src/app.ts",
53 - revealLine: 18,
54 - revealRequestId: 1,
55 - },
56 - },
57 - { openPreview, workspaceAvailable: true },
58 - );
59 - expect(reopened).toBe(true);
60 - const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef);
61 - expect(state.isOpen).toBe(true);
62 - expect(state.surfaces).toMatchObject([{ id: "file:src/app.ts", revealLine: 18 }]);
63 - expect(openPreview).not.toHaveBeenCalled();
64 - });
71 + );
72 + expect(before.surfaces).toEqual([expected]);
73 + panels.closeSurface(threadRef, expected.id);
74 + expect(
75 + selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef).surfaces,
76 + ).toEqual([]);
77 + const entries = useClosedViewStore.getState().entries;
78 + expect(entries).toEqual([
79 + { id: expect.any(String), kind: "panel-tab", threadRef, surface: expected },
80 + ]);
81 + const openPreview = vi.fn();
82 + const reopened = await reopenClosedView(entries[0]!, {
83 + openPreview,
84 + workspaceAvailable: true,
85 + });
86 + expect(reopened).toBe(true);
87 + const state = selectThreadRightPanelState(
88 + useRightPanelStore.getState().byThreadKey,
89 + threadRef,
90 + );
91 + expect(state.isOpen).toBe(true);
92 + expect(state.activeSurfaceId).toBe(expected.id);
93 + expect(state.surfaces).toEqual([expected]);
94 + expect(openPreview).not.toHaveBeenCalled();
95 + },
96 + );
97 +
98 + it.each([
99 + { hosted: false, folderTrail: "packages/contracts/src" },
100 + { hosted: false, folderTrail: undefined },
101 + { hosted: true, folderTrail: "packages/contracts/src" },
102 + { hosted: true, folderTrail: undefined },
103 + ])(
104 + "preserves a hidden root tab with trail $folderTrail (hosted: $hosted)",
105 + async ({ hosted, folderTrail }) => {
106 + const panels = useRightPanelStore.getState();
107 + panels.openFile(threadRef, "apps/web/src");
108 + panels.navigateFolder(threadRef, "file:apps/web/src", "", "apps/web/src");
109 + panels.closeSurface(threadRef, "files");
110 + const entry = useClosedViewStore.getState().entries[0]!;
111 + const hostRef = hosted
112 + ? { ...threadRef, threadId: "host" as ScopedThreadRef["threadId"] }
113 + : threadRef;
114 + const unhost = hosted ? hostRightPanel(threadRef, hostRef) : undefined;
115 + try {
116 + if (folderTrail === undefined) panels.open(threadRef, "files");
117 + else {
118 + panels.openFile(threadRef, folderTrail);
119 + panels.navigateFolder(threadRef, `file:${folderTrail}`, "", folderTrail);
120 + }
121 + panels.close(threadRef);
122 + const before = selectThreadRightPanelState(
123 + useRightPanelStore.getState().byThreadKey,
124 + hostRef,
125 + );
126 + expect(before.isOpen).toBe(false);
127 + const plan = planNextReopen([entry], () => ({
128 + environmentKnown: true,
129 + catalogReady: true,
130 + ownerExists: true,
131 + sideChatExists: true,
132 + shellLive: true,
133 + panel: before,
134 + }));
135 + expect(plan.restore).toBe(entry);
136 + const openPreview = vi.fn();
137 + expect(
138 + await reopenClosedView(plan.restore!, { openPreview, workspaceAvailable: true }),
139 + ).toBe(true);
140 + const after = selectThreadRightPanelState(
141 + useRightPanelStore.getState().byThreadKey,
142 + hostRef,
143 + );
144 + expect(after.isOpen).toBe(true);
145 + expect(after.activeSurfaceId).toBe("files");
146 + expect(after.surfaces).toEqual([
147 + { kind: "files", id: "files", ...(folderTrail === undefined ? {} : { folderTrail }) },
148 + ]);
149 + expect(openPreview).not.toHaveBeenCalled();
150 + } finally {
151 + unhost?.();
152 + }
153 + },
154 + );
155
156 it("does not reopen workspace tabs without an available project", async () => {
157 const options = {
@@ -69,7 +159,7 @@ describe("reopenClosedView", () => {
159 workspaceAvailable: false,
160 };
161 for (const surface of [
72 - { kind: "files", id: "files" },
162 + { kind: "files", id: "files", folderTrail: "apps/web/src" },
163 {
164 kind: "file",
165 id: "file:src/app.ts",
@@ -77,6 +167,14 @@ describe("reopenClosedView", () => {
167 revealLine: null,
168 revealRequestId: 0,
169 },
170 + {
171 + kind: "file",
172 + id: "file:apps",
173 + relativePath: "apps",
174 + revealLine: null,
175 + revealRequestId: 1,
176 + folderTrail: "apps/web/src",
177 + },
178 ] as const) {
179 expect(await reopenClosedView({ kind: "panel-tab", threadRef, surface }, options)).toBe(
180 false,
apps/web/src/reopenClosedView.ts
+19 -1
@@ -5,7 +5,9 @@ import type { ClosedView, ClosedViewEntry } from "./closedViewStore";
5 import type { PullRequestListPreferences } from "./components/pullRequest/pullRequestListPreferences";
6 import { openPreviewSession } from "./components/preview/openPreviewSession";
7 import {
8 + rightPanelHostRef,
9 type RightPanelSurface,
10 + selectThreadRightPanelState,
11 type ThreadRightPanelState,
12 useRightPanelStore,
13 } from "./rightPanelStore";
@@ -125,8 +127,24 @@ export async function reopenClosedView(
127 break;
128 case "file":
129 if (surface.attachment) panels.openAttachment(ref, surface.attachment);
128 - else panels.openFile(ref, surface.relativePath, surface.revealLine ?? undefined);
130 + else {
131 + panels.openFile(ref, surface.relativePath, surface.revealLine ?? undefined);
132 + if (typeof surface.folderTrail === "string") {
133 + panels.navigateFolder(ref, surface.id, surface.relativePath, surface.folderTrail);
134 + }
135 + }
136 + break;
137 + case "files": {
138 + const rootAlreadyExists = selectThreadRightPanelState(
139 + panels.byThreadKey,
140 + rightPanelHostRef(ref),
141 + ).surfaces.some((current) => current.kind === "files");
142 + panels.open(ref, "files");
143 + if (!rootAlreadyExists && typeof surface.folderTrail === "string") {
144 + panels.navigateFolder(ref, surface.id, "", surface.folderTrail);
145 + }
146 break;
147 + }
148 case "device":
149 if (surface.target) {
150 panels.openDevice(ref, surface.target);