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, 10:45 UTC
fix(web): keep later navigation when thread archival completes (#24109)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Oct 30, 2026 at 16:03 UTC
c84acfa2054c1ec99c5428edb2ed57e723291403
3 files changed
+36
-4
apps/web/src/hooks/useThreadActions.permissions.test.ts
+1
-1
@@ -43,7 +43,7 @@ vi.mock("react", () => ({
43
useRef: (current: unknown) => ({ current }),
44
}));
45
vi.mock("@tanstack/react-router", () => ({
46
- useRouter: () => ({ state: { matches: [] }, navigate: async () => {} }),
46
+ useRouter: () => ({ state: { location: { href: "/" }, matches: [] }, navigate: async () => {} }),
47
}));
48
vi.mock("../state/session", () => ({
49
environmentSession: { sessionStateAtom: "session" },
apps/web/src/hooks/useThreadActions.ts
+2
-1
@@ -374,6 +374,7 @@ export function useThreadActions() {
374
);
375
}
376
377
+ const requestingRouteHref = router.state.location.href;
378
const currentRouteThreadRef = getCurrentRouteThreadRef();
379
const shouldNavigateToDraft =
380
currentRouteThreadRef?.threadId === threadRef.threadId &&
@@ -400,7 +401,7 @@ export function useThreadActions() {
401
failureTitle: "Failed to undo archive",
402
});
403
403
- if (shouldNavigateToDraft) {
404
+ if (shouldNavigateToDraft && router.state.location.href === requestingRouteHref) {
405
const navigationResult = await settlePromise(() =>
406
handleNewThread(scopeProjectRef(thread.environmentId, thread.projectId)),
407
);
apps/web/src/hooks/useThreadActions.undo.test.ts
+33
-2
@@ -19,7 +19,7 @@ const commands = vi.hoisted(() => ({
19
}));
20
const router = vi.hoisted(() => ({
21
navigate: vi.fn(async () => {}),
22
- state: { matches: [{ params: {} as Record<string, string> }] },
22
+ state: { location: { href: "/" }, matches: [{ params: {} as Record<string, string> }] },
23
}));
24
vi.mock("../state/use-atom-query-runner", () => ({ useAtomQueryRunner: () => vi.fn() }));
25
vi.mock("../state/session", async (original) => ({
@@ -34,7 +34,11 @@ vi.mock("react", async (original) => ({
34
}));
35
vi.mock("@tanstack/react-router", () => ({ useRouter: () => router }));
36
vi.mock("./useSettings", () => ({ useClientSettings: () => false }));
37
-vi.mock("./useHandleNewThread", () => ({ useNewThreadHandler: () => vi.fn() }));
37
+vi.mock("./useHandleNewThread", () => ({
38
+ useNewThreadHandler: () => async () => {
39
+ router.state.location.href = "/draft/project";
40
+ },
41
+}));
42
vi.mock("../composerDraftStore", () => ({ useComposerDraftStore: () => vi.fn() }));
43
vi.mock("../terminalUiStateStore", () => ({ useTerminalUiStateStore: () => vi.fn() }));
44
vi.mock("../uiStateStore", () => ({ useUiStateStore: () => vi.fn() }));
@@ -94,6 +98,7 @@ beforeEach(() => {
98
command.mockReset().mockResolvedValue({ _tag: "Success", value: undefined });
99
}
100
router.navigate.mockClear();
101
+ router.state.location.href = "/";
102
router.state.matches[0]!.params = {};
103
threadShell.pinnedAt = null;
104
threadShell.snoozedUntil = null;
@@ -201,6 +206,32 @@ describe("archive Undo", () => {
206
});
207
});
208
209
+describe("archive navigation", () => {
210
+ it.each([
211
+ { destination: "/undo-env/thread", expected: "/draft/project" },
212
+ { destination: "/undo-env/other-thread", expected: "/undo-env/other-thread" },
213
+ { destination: "/settings", expected: "/settings" },
214
+ ])("ends at $expected after opening $destination while archiving", async (route) => {
215
+ router.state.location.href = "/undo-env/thread";
216
+ router.state.matches[0]!.params = {
217
+ environmentId: target.environmentId,
218
+ threadId: target.threadId,
219
+ };
220
+ let finishArchive!: () => void;
221
+ commands.archive.mockReturnValue(
222
+ new Promise((resolve) => {
223
+ finishArchive = () => resolve({ _tag: "Success", value: undefined });
224
+ }),
225
+ );
226
+ const archived = useThreadActions().archiveThread(target);
227
+ router.state.location.href = route.destination;
228
+ finishArchive();
229
+ expect((await archived)._tag).toBe("Success");
230
+ expect(useThreadUndoNotice.getState().notice).toMatchObject({ action: "Archived" });
231
+ expect(router.state.location.href).toBe(route.expected);
232
+ });
233
+});
234
+
235
describe("settle and snooze Undo", () => {
236
it("un-settles from the notice and expires the Undo after a manual un-settle", async () => {
237
const add = vi.spyOn(toastManager, "add").mockReturnValue("toast");