@devries-cameron20 / t3code-1 / commits / 31eb1d0076
Fork 0

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

fix(web): closing Settings or Usage no longer jumps back to a quote's source (#29013)

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

Julius Marminge committed Nov 3, 2026 at 12:00 UTC 31eb1d00765672969b0dc1b27caef78a0c4b2e36
3 files changed +87 -1
apps/web/src/components/sidebar/mainAppLocation.browser.test.tsx new
+77
@@ -0,0 +1,77 @@
1 +import { EnvironmentId, MessageId, ThreadId, type AssistantCitation } from "@t3tools/contracts";
2 +import type { AnyRouter } from "@tanstack/react-router";
3 +import { describe, expect, it, vi } from "vite-plus/test";
4 +import { userEvent } from "vite-plus/test/browser";
5 +
6 +import { render } from "../../../test/render";
7 +import {
8 + assistantCitationFromLocation,
9 + assistantCitationNavigation,
10 +} from "../../lib/assistantCitationNavigation";
11 +import {
12 + startMainAppLocationTracking,
13 + useCloseAppModal,
14 + useNavigateToMainApp,
15 +} from "./mainAppLocation";
16 +
17 +const THREAD_PATH = "/environment-one/thread-one";
18 +
19 +const citation: AssistantCitation = {
20 + version: 1,
21 + environmentId: EnvironmentId.make("environment-one"),
22 + threadId: ThreadId.make("thread-one"),
23 + messageId: MessageId.make("assistant-one"),
24 + text: "quoted reply",
25 + start: 0,
26 + end: 12,
27 + prefix: "",
28 + suffix: "",
29 +};
30 +
31 +function ReturnControls() {
32 + const closeAppModal = useCloseAppModal();
33 + const navigateToMainApp = useNavigateToMainApp();
34 + return (
35 + <>
36 + <button type="button" onClick={() => void closeAppModal()}>
37 + Close modal
38 + </button>
39 + <button type="button" onClick={() => void navigateToMainApp()}>
40 + Back to app
41 + </button>
42 + </>
43 + );
44 +}
45 +
46 +// The tracker records on onResolved, which the router emits only once React commits the page.
47 +async function settled(router: AnyRouter, navigation: Promise<void>) {
48 + await navigation;
49 + await vi.waitFor(() =>
50 + expect(router.state.resolvedLocation?.href).toBe(router.state.location.href),
51 + );
52 +}
53 +
54 +describe("main app return location", () => {
55 + it("returns to the thread without re-opening the quote source it was opened at", async () => {
56 + await using screen = await render(<ReturnControls />, { router: THREAD_PATH });
57 + const router = screen.router!;
58 + using _tracking = { [Symbol.dispose]: startMainAppLocationTracking(router) };
59 +
60 + const returnLocation = async (from: string, control: string) => {
61 + await settled(router, router.navigate(assistantCitationNavigation(citation)));
62 + expect(assistantCitationFromLocation(router.state.location.href)).toEqual(citation);
63 + await settled(router, router.navigate({ href: from }));
64 + await userEvent.click(screen.getByRole("button", { name: control }));
65 + await vi.waitFor(() => expect(router.state.location.pathname).toBe(THREAD_PATH));
66 + return router.state.location.href;
67 + };
68 +
69 + const closingUsage = await returnLocation("/usage", "Close modal");
70 + const sidebarBack = await returnLocation("/pull-requests", "Back to app");
71 +
72 + expect({ closingUsage, sidebarBack }).toEqual({
73 + closingUsage: THREAD_PATH,
74 + sidebarBack: THREAD_PATH,
75 + });
76 + });
77 +});
apps/web/src/components/sidebar/mainAppLocation.ts
+3 -1
@@ -1,6 +1,7 @@
1 import { useNavigate, type AnyRouter } from "@tanstack/react-router";
2
3 import { GUEST_PAGE_PATH } from "../../guestPage";
4 +import { withoutAssistantCitationHash } from "../../lib/assistantCitationNavigation";
5
6 /** Settings and Usage open as modals over the last main-app view. */
7 export function isAppModalPage(pathname: string) {
@@ -22,8 +23,9 @@ let appModalReturnHref: string | null = null;
23 /** Remembers where Settings, Usage, and the utility pages lead back to. */
24 export function startMainAppLocationTracking(router: AnyRouter): () => void {
25 const record = () => {
25 - const { pathname, href } = router.state.location;
26 + const { pathname } = router.state.location;
27 if (isAppModalPage(pathname) || SHELL_LESS_PATHS.has(pathname)) return;
28 + const href = withoutAssistantCitationHash(router.state.location.href);
29 appModalReturnHref = href;
30 if (!isSidebarUtilityPage(pathname)) mainAppHref = href;
31 };
apps/web/src/lib/assistantCitationNavigation.ts
+7
@@ -39,6 +39,13 @@ export function assistantCitationFromLocation(href: string) {
39 }
40 }
41
42 +/** Return paths drop the quote hash so going back does not reveal its source again. */
43 +export function withoutAssistantCitationHash(href: string) {
44 + const hashIndex = href.indexOf("#");
45 + if (hashIndex === -1 || !href.startsWith(CITATION_HASH_PREFIX, hashIndex + 1)) return href;
46 + return href.slice(0, hashIndex);
47 +}
48 +
49 /** A fresh activation lets the same link reveal its source again after dismissal. */
50 export function assistantCitationNavigation(citation: AssistantCitation) {
51 return {