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, 00:45 UTC
fix(web): thread navigation shortcuts honor previewFocus and previewOpen conditions (#29678)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 10, 2026 at 01:32 UTC
75200f45c6bb17dda18f589ef71db341af9a3e08
2 files changed
+113
apps/web/src/components/Sidebar.shortcuts.browser.test.tsx
new
+103
@@ -0,0 +1,103 @@
1
+import { createMemoryHistory } from "@tanstack/react-router";
2
+import { scopeThreadRef } from "@t3tools/client-runtime/environment";
3
+import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
4
+import type * as Context from "effect/Context";
5
+import { expect, it, vi } from "vite-plus/test";
6
+import { page, userEvent } from "vite-plus/test/browser";
7
+
8
+import { AppRoot } from "~/AppRoot";
9
+// The thread route loads ChatView lazily; its first transform would eat the test's timeout.
10
+import "~/components/ChatView";
11
+import { __setClientSettingsForTests } from "~/hooks/useSettings";
12
+import { useRightPanelStore } from "~/rightPanelStore";
13
+import { getRouter } from "~/router";
14
+import {
15
+ ENVIRONMENT_ID,
16
+ installFakeEnvironment,
17
+ threadWithHistory,
18
+ type FakeDriver,
19
+} from "../../test/fakeEnvironment";
20
+import { act, render } from "../../test/render";
21
+
22
+// The socket is the only fake layer; see test/appScenarios.renders.tsx.
23
+vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => {
24
+ const [actual, { fakeDriver }, Layer] = await Promise.all([
25
+ importOriginal<{ readonly ConnectionDriver: Context.Key<unknown, FakeDriver> }>(),
26
+ import("../../test/fakeEnvironment"),
27
+ import("effect/Layer"),
28
+ ]);
29
+ return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) };
30
+});
31
+
32
+vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
33
+ ...(await original()),
34
+ trackRpcRequestSent: () => {},
35
+}));
36
+
37
+vi.mock(import("~/state/server"), async (original) => {
38
+ const actual = await original();
39
+ const { Atom } = await import("effect/reactivity");
40
+ const { compileResolvedKeybindingsConfig } = await import("@t3tools/shared/keybindings");
41
+ const keybindings = compileResolvedKeybindingsConfig([
42
+ { key: "mod+shift+]", command: "thread.next", when: "!previewFocus && !previewOpen" },
43
+ { key: "mod+1", command: "thread.jump.1", when: "!previewFocus" },
44
+ ]);
45
+ return { ...actual, primaryServerKeybindingsAtom: Atom.make(keybindings) };
46
+});
47
+
48
+it("leaves thread shortcuts and their hints to the preview when their rules exclude it", async () => {
49
+ const [first, second] = [threadWithHistory("thread-a", 1), threadWithHistory("thread-b", 1)];
50
+ using _environment = installFakeEnvironment([first, second]);
51
+ using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("Linux x86_64");
52
+ __setClientSettingsForTests({
53
+ ...DEFAULT_CLIENT_SETTINGS,
54
+ onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
55
+ });
56
+ await page.viewport(1400, 900);
57
+ const router = getRouter(
58
+ createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${first.id}`] }),
59
+ );
60
+ await router.load();
61
+ await using _app = await render(<AppRoot router={router} />, {
62
+ // AppRoot brings its own router.
63
+ router: false,
64
+ });
65
+ await expect.element(page.getByText(`Thread ${second.id}`).first()).toBeVisible();
66
+
67
+ const previewChrome = document.createElement("div");
68
+ previewChrome.dataset.previewPanelMode = "browser";
69
+ previewChrome.innerHTML = '<button type="button">Reload</button>';
70
+ document.body.append(previewChrome);
71
+ using _chrome = { [Symbol.dispose]: () => previewChrome.remove() };
72
+
73
+ const press = () => userEvent.keyboard("{Control>}{Shift>}]{/Shift}{/Control}");
74
+ const jumpHint = () => document.querySelector("[data-jump-hint]");
75
+ const whileHoldingControl = async (assertJumpHints: () => void) => {
76
+ // Every deadline reads as due on subscribe, so hints skip the hold delay.
77
+ let now = Date.parse("2026-01-01T00:00:00.000Z");
78
+ using _clock = vi.spyOn(Date, "now").mockImplementation(() => (now += 1000));
79
+ await userEvent.keyboard("{Control>}");
80
+ await act(() => {});
81
+ await vi.waitFor(assertJumpHints);
82
+ await userEvent.keyboard("{/Control}");
83
+ };
84
+ const firstPath = `/${ENVIRONMENT_ID}/${first.id}`;
85
+
86
+ await userEvent.click(page.getByRole("button", { name: "Reload" }));
87
+ await press();
88
+ expect(router.history.location.pathname).toBe(firstPath);
89
+ await whileHoldingControl(() => expect(jumpHint()).toBeNull());
90
+
91
+ const firstRef = scopeThreadRef(ENVIRONMENT_ID, first.id);
92
+ await act(() => useRightPanelStore.getState().openBrowser(firstRef, null));
93
+ if (document.activeElement instanceof HTMLElement) document.activeElement.blur();
94
+ await press();
95
+ expect(router.history.location.pathname).toBe(firstPath);
96
+
97
+ await act(() => useRightPanelStore.getState().close(firstRef));
98
+ await press();
99
+ await vi.waitFor(() =>
100
+ expect(router.history.location.pathname).toBe(`/${ENVIRONMENT_ID}/${second.id}`),
101
+ );
102
+ await whileHoldingControl(() => expect(jumpHint()).not.toBeNull());
103
+});
apps/web/src/components/Sidebar.tsx
+10
@@ -99,8 +99,10 @@ import {
99
} from "../keybindings";
100
import { useShortcutModifierState } from "../shortcutModifierState";
101
import { isTerminalFocused } from "../lib/terminalFocus";
102
+import { isPreviewFocused } from "../lib/previewFocus";
103
import { isModelPickerOpen } from "../modelPickerVisibility";
104
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
105
+import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
106
import { isMacPlatform } from "~/lib/utils";
107
import { readLocalApi } from "../localApi";
108
import { configuredHostedAppUrl } from "../hostedPairing";
@@ -2883,6 +2885,9 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2885
? selectThreadTerminalUiState(state.terminalUiStateByThreadKey, routeThreadRef).terminalOpen
2886
: false,
2887
);
2888
+ const routePreviewOpen = useRightPanelStore(
2889
+ (state) => selectActiveRightPanel(state.byThreadKey, routeThreadRef) === "preview",
2890
+ );
2891
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to window keydown for thread navigation shortcuts using the current thread list
2892
useEffect(() => {
2893
const onWindowKeyDown = (event: KeyboardEvent) => {
@@ -2894,6 +2899,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2899
context: {
2900
terminalFocus: isTerminalFocused(),
2901
terminalOpen: routeTerminalOpen,
2902
+ previewFocus: isPreviewFocused(),
2903
+ previewOpen: routePreviewOpen,
2904
modelPickerOpen: isModelPickerOpen(),
2905
isWeb: !isElectron,
2906
isDesktop: isElectron,
@@ -2929,6 +2936,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2936
keybindings,
2937
navigateToThread,
2938
orderedThreadKeys,
2939
+ routePreviewOpen,
2940
routeRowThreadKey,
2941
routeTerminalOpen,
2942
threadByKey,
@@ -2942,6 +2950,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2950
context: {
2951
terminalFocus: terminalFocused,
2952
terminalOpen: routeTerminalOpen,
2953
+ previewFocus: isPreviewFocused(),
2954
+ previewOpen: routePreviewOpen,
2955
modelPickerOpen: isModelPickerOpen(),
2956
isWeb: !isElectron,
2957
isDesktop: isElectron,