@devries-cameron20 / t3code Mirror · read-only / commits / 2579c3c4dd
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 21, 11:00 UTC

fix(web): close Usage without reloading (#37272)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Dustin Loring committed Nov 15, 2026 at 11:49 UTC 2579c3c4dd25c2a8572af53724b7cd6e87643483
4 files changed +21 -2
apps/web/src/authBootstrap.test.ts
+2
@@ -328,7 +328,9 @@ describe("resolveInitialServerAuthGateState", () => {
328 await expect(resolveInitialServerAuthGateState()).resolves.toEqual(requiresAuth);
329
330 // Token removal synchronously reloads the TanStack auth gate via replaceState.
331 + const pairingHistoryState = history.location.state;
332 const token = takePairingTokenFromUrl();
333 + expect(history.location.state).toEqual(pairingHistoryState);
334 expect(gateLoads).toHaveLength(1);
335 await expect(gateLoads[0]).resolves.toEqual(requiresAuth);
336 const rejected = expect(submitServerAuthCredential(token!)).rejects.toMatchObject({
apps/web/src/components/sidebar/mainAppLocation.browser.test.tsx
+13
@@ -52,6 +52,19 @@ async function settled(router: AnyRouter, navigation: Promise<void>) {
52 }
53
54 describe("main app return location", () => {
55 + it("closes Usage without leaving the current document when the app started with history", async () => {
56 + await using screen = await render(<ReturnControls />, { router: "/" });
57 + const router = screen.router!;
58 + await settled(router, router.navigate({ href: THREAD_PATH }));
59 + using _tracking = { [Symbol.dispose]: startMainAppLocationTracking(router) };
60 + using go = vi.spyOn(router.history, "go");
61 +
62 + await settled(router, router.navigate({ href: "/usage" }));
63 + await userEvent.click(screen.getByRole("button", { name: "Close modal" }));
64 + await vi.waitFor(() => expect(router.state.location.pathname).toBe(THREAD_PATH));
65 + expect(go).not.toHaveBeenCalled();
66 + });
67 +
68 it("returns to the thread without re-opening the quote source it was opened at", async () => {
69 await using screen = await render(<ReturnControls />, { router: THREAD_PATH });
70 const router = screen.router!;
apps/web/src/components/sidebar/mainAppLocation.ts
+5 -1
@@ -22,9 +22,11 @@ let mainAppHref: string | null = null;
22 let appModalReturnHref: string | null = null;
23 let appModalReturnHistoryIndex: number | null = null;
24 let appModalReturnThreadTarget: ThreadRouteTarget | null = null;
25 +let initialHistoryIndex = 0;
26
27 /** Remembers where Settings, Usage, and the utility pages lead back to. */
28 export function startMainAppLocationTracking(router: AnyRouter): () => void {
29 + initialHistoryIndex = router.state.location.state.__TSR_index;
30 const record = () => {
31 const { pathname } = router.state.location;
32 if (isAppModalPage(pathname) || SHELL_LESS_PATHS.has(pathname)) return;
@@ -60,7 +62,9 @@ export function useCloseAppModal() {
62 const href = appModalReturnHref ?? mainAppHref ?? "/";
63 const returnIndex = appModalReturnHistoryIndex ?? 0;
64 const steps = router.state.location.state.__TSR_index - returnIndex;
63 - if (returnIndex === 0 || steps <= 0) return navigate({ href });
65 + // Stepping back past this document's first entry reloads the page. Written as a negated
66 + // comparison so a missing (NaN) history index also falls back to client navigation.
67 + if (!(returnIndex > initialHistoryIndex && steps > 0)) return navigate({ href, replace: true });
68 // Go back to the entry before the return page and push it again: only a push drops the
69 // modal's entries from forward history, and reusing the old entry avoids a duplicate stop.
70 const unsubscribe = router.history.subscribe(() => {
apps/web/src/environments/primary/auth.ts
+1 -1
@@ -151,7 +151,7 @@ export function stripPairingTokenFromUrl() {
151 if (next.toString() === url.toString()) {
152 return;
153 }
154 - window.history.replaceState({}, document.title, next.toString());
154 + window.history.replaceState(window.history.state, document.title, next.toString());
155 }
156
157 export function takePairingTokenFromUrl(): string | null {