@devries-cameron20 / t3code Mirror · read-only / commits / da95a04763
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, 12:15 UTC

fix(web): right-panel shortcuts work on a new, unsent thread (#35189)

Julius Marminge committed Nov 14, 2026 at 20:51 UTC da95a04763163dc7ccd213de3a14f3eaefea2dfc
2 files changed +42 -2
apps/web/src/shortcuts/chatRouteCommands.test.ts
+33
@@ -3,11 +3,14 @@ import type { AnyRouter } from "@tanstack/react-router";
3 import { describe, expect, it, vi } from "vite-plus/test";
4
5 import * as commandPalette from "../commandPaletteBus";
6 +import { DraftId, useComposerDraftStore } from "../composerDraftStore";
7 +import * as previewActions from "../components/preview/previewActionBus";
8 import * as settings from "../hooks/useSettings";
9 import * as storage from "../hooks/useLocalStorage";
10 import * as threadActions from "../lib/chatThreadActions";
11 import * as entities from "../state/entities";
12 import * as projectsState from "../state/projects";
13 +import * as session from "../state/session";
14 import { Atom } from "effect/reactivity";
15 import type { Project } from "../types";
16 import { installChatRouteCommands } from "./chatRouteCommands";
@@ -73,3 +76,33 @@ describe("new thread commands", () => {
76 }
77 });
78 });
79 +
80 +describe("preview commands", () => {
81 + it.each([
82 + { command: "preview.find", action: "find" },
83 + { command: "preview.refresh", action: "refresh" },
84 + { command: "preview.focusUrl", action: "focus-url" },
85 + ] as const)("$command reaches the right panel on a draft thread", ({ command, action }) => {
86 + const draftId = DraftId.make("draft-1");
87 + useComposerDraftStore
88 + .getState()
89 + .setProjectDraftThreadId(
90 + { environmentId: EnvironmentId.make("local"), projectId: ProjectId.make("active") },
91 + draftId,
92 + );
93 + using stack = new DisposableStack();
94 + stack.defer(() => useComposerDraftStore.getState().clearDraftThread(draftId));
95 + using _scope = vi.spyOn(session, "readEnvironmentScope").mockReturnValue(true);
96 + using dispatch = vi.spyOn(previewActions, "dispatchPreviewAction").mockImplementation(() => {});
97 + using register = vi.spyOn(dispatcher, "registerCommands").mockReturnValue(() => {});
98 + const router = {
99 + state: { matches: [{ routeId: "/_chat/draft/$draftId", params: { draftId } }] },
100 + } as unknown as AnyRouter;
101 + stack.defer(installChatRouteCommands(router));
102 + const event = { preventDefault: vi.fn(), stopPropagation: vi.fn() } as unknown as KeyboardEvent;
103 +
104 + register.mock.calls[0]![0][command]!(event);
105 +
106 + expect(dispatch).toHaveBeenCalledWith(action);
107 + });
108 +});
apps/web/src/shortcuts/chatRouteCommands.ts
+9 -2
@@ -55,6 +55,13 @@ export function installChatRouteCommands(router: AnyRouter): () => void {
55 const target = readRouteTarget();
56 return target?.kind === "server" ? target.threadRef : null;
57 };
58 + const readRouteEnvironmentId = () => {
59 + const target = readRouteTarget();
60 + if (!target) return null;
61 + return target.kind === "server"
62 + ? target.threadRef.environmentId
63 + : (useComposerDraftStore.getState().getDraftSession(target.draftId)?.environmentId ?? null);
64 + };
65 const readPreviewOpen = () => {
66 const threadRef = readRouteThreadRef();
67 // Store-only on purpose: the URL-aware arbitration lives in ChatView's
@@ -114,8 +121,8 @@ export function installChatRouteCommands(router: AnyRouter): () => void {
121 (action: PreviewAction): CommandHandler =>
122 (event) => {
123 claim(event);
117 - const threadRef = readRouteThreadRef();
118 - if (threadRef && canOperatePreview(threadRef.environmentId)) dispatchPreviewAction(action);
124 + const environmentId = readRouteEnvironmentId();
125 + if (environmentId && canOperatePreview(environmentId)) dispatchPreviewAction(action);
126 };
127
128 return registerCommands(