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

fix(web): mouse back/forward over the right panel no longer moves the main chat (#30882)

Julius Marminge committed Nov 11, 2026 at 17:16 UTC 7c76c9ddc2710c13f55421a92600ea7123c833bf
10 files changed +189 -1
apps/web/src/browser/HostedBrowserWebview.tsx
+12
@@ -7,6 +7,10 @@ import { useShallow } from "zustand/react/shallow";
7 import { useEffect, useEffectEvent, useRef, useState } from "react";
8
9 import { previewBridge } from "~/components/preview/previewBridge";
10 +import {
11 + preventThumbButtonFocus,
12 + takeThumbButtonNavigation,
13 +} from "~/components/preview/thumbButtons";
14 import { usePreviewBridge } from "~/components/preview/usePreviewBridge";
15 import { useClientSettingsHydrated } from "~/hooks/useSettings";
16 import { cn, isMacPlatform } from "~/lib/utils";
@@ -302,6 +306,12 @@ export function HostedBrowserWebview(props: {
306
307 if (!clientSettingsHydrated || !config) return null;
308
309 + // This fixed wrapper sits outside the right panel shell, so it takes thumb presses itself.
310 + const navigateThumb = (direction: "back" | "forward") => {
311 + if (direction === "back") void previewBridge?.goBack(runtimeTabId);
312 + else void previewBridge?.goForward(runtimeTabId);
313 + };
314 +
315 const renderingActive = active || backgroundActivity || pictureInPicture || recordingActive;
316 const wrapperStyle = resolveHostedBrowserWebviewWrapperStyle({
317 active,
@@ -320,6 +330,8 @@ export function HostedBrowserWebview(props: {
330 className="fixed overflow-hidden bg-muted/35"
331 style={{ ...wrapperStyle, overscrollBehavior: "contain" }}
332 onScroll={syncContentPresentation}
333 + onMouseDown={preventThumbButtonFocus}
334 + onMouseUp={(event) => takeThumbButtonNavigation(event, navigateThumb)}
335 data-preview-rendering={renderingActive ? "active" : "suspended"}
336 data-preview-viewport={runtimeTabId}
337 >
apps/web/src/components/RightPanelTabs.browser.test.tsx
+116 -1
@@ -1,11 +1,14 @@
1 import "~/index.css";
2
3 +import { EnvironmentId } from "@t3tools/contracts";
4 import { describe, expect, it, vi } from "vite-plus/test";
5
6 +import { InputGroup, InputGroupAddon, InputGroupInput } from "~/components/ui/input-group";
7 import type { RightPanelSurface } from "~/rightPanelStore";
8 import { render, stubGlobal } from "../../test/render";
9 import { HistorySwipeNavigation } from "./HistorySwipeNavigation";
8 -import { RightPanelTabs } from "./RightPanelTabs";
10 +import { RightPanelTabs, type RightPanelTabsProps } from "./RightPanelTabs";
11 +import { subscribePreviewAction } from "./preview/previewActionBus";
12
13 const navigateHistory = vi.hoisted(() => vi.fn());
14 vi.mock("../navigationHistory", () => ({ canNavigateHistory: () => true, navigateHistory }));
@@ -134,3 +137,115 @@ describe("RightPanelTabs", () => {
137 expect(navigateHistory).toHaveBeenCalledExactlyOnceWith("back");
138 });
139 });
140 +
141 +const BROWSER_SURFACE: RightPanelSurface = {
142 + id: "browser:tab-1",
143 + kind: "preview",
144 + resourceId: "tab-1",
145 +};
146 +const DIFF_SURFACE: RightPanelSurface = { id: "diff", kind: "diff" };
147 +
148 +function panel(activeSurface: RightPanelSurface) {
149 + const noop = () => {};
150 + const props: RightPanelTabsProps = {
151 + mode: "inline",
152 + keybindings: [],
153 + getShortcutContext: () => ({
154 + terminalFocus: false,
155 + terminalOpen: false,
156 + previewFocus: false,
157 + previewOpen: true,
158 + isWeb: true,
159 + isDesktop: false,
160 + }),
161 + surfaces: [BROWSER_SURFACE, DIFF_SURFACE],
162 + environmentId: EnvironmentId.make("environment-local"),
163 + activeSurfaceId: activeSurface.id,
164 + pendingSurfaceIds: new Set(),
165 + previewSessions: {},
166 + desktopByTabId: {},
167 + terminalLabelsById: new Map(),
168 + onActivate: noop,
169 + onCloseSurface: noop,
170 + onCloseOtherSurfaces: noop,
171 + onCloseSurfacesToRight: noop,
172 + onCloseAllSurfaces: noop,
173 + onCopyFilePath: noop,
174 + onAddBrowser: noop,
175 + onAddBrowserInProfile: noop,
176 + onAddTerminal: noop,
177 + onAddDiff: noop,
178 + onAddFiles: noop,
179 + onAddPullRequest: noop,
180 + onAddPullRequests: noop,
181 + onAddDevice: noop,
182 + browserAvailable: true,
183 + terminalAvailable: true,
184 + diffAvailable: true,
185 + filesAvailable: true,
186 + pullRequestAvailable: true,
187 + pullRequestsAvailable: true,
188 + deviceAvailable: true,
189 + children: (
190 + <div data-testid="surface-content">
191 + {/* Stands in for ServerBrowserSurface, whose page canvas handles thumb buttons itself. */}
192 + <canvas data-testid="page-canvas" onMouseUp={(event) => event.preventDefault()} />
193 + <InputGroup>
194 + <InputGroupInput aria-label="Address" />
195 + <InputGroupAddon data-testid="address-addon" align="inline-end" />
196 + </InputGroup>
197 + </div>
198 + ),
199 + };
200 + return <RightPanelTabs {...props} />;
201 +}
202 +
203 +// Chromium focuses on an uncancelled mousedown and runs history back/forward on an
204 +// uncancelled button 3/4 mouseup.
205 +function releaseThumbButton(
206 + target: Element,
207 + button: 3 | 4,
208 +): { focusMoved: boolean; routerMoved: boolean } {
209 + const focused = document.activeElement;
210 + const down = new MouseEvent("mousedown", { bubbles: true, cancelable: true, button });
211 + const up = new MouseEvent("mouseup", { bubbles: true, cancelable: true, button });
212 + target.dispatchEvent(down);
213 + target.dispatchEvent(up);
214 + return {
215 + focusMoved: !down.defaultPrevented || document.activeElement !== focused,
216 + routerMoved: !up.defaultPrevented,
217 + };
218 +}
219 +
220 +const STAYS_PUT = { focusMoved: false, routerMoved: false };
221 +
222 +describe("right panel thumb buttons", () => {
223 + it("keep the app router still over a surface that is not a browser", async () => {
224 + await using screen = await render(panel(DIFF_SURFACE));
225 + const tabStrip = screen.container.querySelector("[data-right-panel-tabbar]")!;
226 + const content = screen.getByTestId("surface-content").element();
227 +
228 + expect(releaseThumbButton(tabStrip, 3)).toEqual(STAYS_PUT);
229 + expect(releaseThumbButton(tabStrip, 4)).toEqual(STAYS_PUT);
230 + expect(releaseThumbButton(content, 3)).toEqual(STAYS_PUT);
231 + expect(releaseThumbButton(content, 4)).toEqual(STAYS_PUT);
232 + });
233 +
234 + it("go back and forward in the active browser tab instead of the app router", async () => {
235 + const actions: string[] = [];
236 + using _subscription = { [Symbol.dispose]: subscribePreviewAction((a) => actions.push(a)) };
237 + await using screen = await render(panel(BROWSER_SURFACE));
238 + const tabStrip = screen.container.querySelector("[data-right-panel-tabbar]")!;
239 + const content = screen.getByTestId("surface-content").element();
240 +
241 + expect(releaseThumbButton(tabStrip, 3)).toEqual(STAYS_PUT);
242 + expect(releaseThumbButton(content, 4)).toEqual(STAYS_PUT);
243 + // The address addon focuses its input on press; a thumb press must leave focus alone.
244 + expect(releaseThumbButton(screen.getByTestId("address-addon").element(), 3)).toEqual(STAYS_PUT);
245 + expect(actions).toEqual(["back", "forward", "back"]);
246 +
247 + // The page canvas already went back in the tab; the panel must not go back a second time.
248 + releaseThumbButton(screen.getByTestId("page-canvas").element(), 3);
249 + expect(actions).toEqual(["back", "forward", "back"]);
250 + });
251 +});
apps/web/src/components/RightPanelTabs.tsx
+9
@@ -99,6 +99,8 @@ import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
99 import { PreviewPanelShell, type PreviewPanelMode } from "./preview/PreviewPanelShell";
100 import { FaviconImage } from "./preview/PreviewFaviconIcon";
101 import { previewBridge } from "./preview/previewBridge";
102 +import { dispatchPreviewAction } from "./preview/previewActionBus";
103 +import { preventThumbButtonFocus, takeThumbButtonNavigation } from "./preview/thumbButtons";
104 import { PierreEntryIcon } from "./chat/PierreEntryIcon";
105 import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
106 import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
@@ -1335,6 +1337,13 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
1337 {...(props.widthStorageKey !== undefined ? { widthStorageKey: props.widthStorageKey } : {})}
1338 {...(props.defaultWidth !== undefined ? { defaultWidth: props.defaultWidth } : {})}
1339 {...(props.inlineSize ? { inlineSize: props.inlineSize } : {})}
1340 + onMouseDown={preventThumbButtonFocus}
1341 + onMouseUp={(event) =>
1342 + takeThumbButtonNavigation(
1343 + event,
1344 + focusedSurface?.kind === "preview" ? dispatchPreviewAction : undefined,
1345 + )
1346 + }
1347 >
1348 <div
1349 className={cn(
apps/web/src/components/preview/PreviewPanelShell.tsx
+5
@@ -1,6 +1,7 @@
1 import {
2 type CSSProperties,
3 type FocusEvent,
4 + type MouseEventHandler,
5 type ReactNode,
6 useLayoutEffect,
7 useRef,
@@ -29,6 +30,8 @@ interface PreviewPanelShellProps {
30 /** Use a distinct key per surface to keep remembered widths independent. */
31 widthStorageKey?: string;
32 defaultWidth?: number;
33 + onMouseDown?: MouseEventHandler<HTMLDivElement>;
34 + onMouseUp?: MouseEventHandler<HTMLDivElement>;
35 children: ReactNode;
36 }
37
@@ -153,6 +156,8 @@ function PreviewPanelShellFrame(
156 {...(props.workspaceArea ? panelArea : {})}
157 data-workspace-focus-key={props.workspaceFocusKey}
158 data-workspace-unavailable={collapsible && !open ? "true" : undefined}
159 + onMouseDown={props.onMouseDown}
160 + onMouseUp={props.onMouseUp}
161 className={cn(
162 "relative flex h-full min-h-0 min-w-0 max-w-full flex-col self-stretch bg-background",
163 isInline
apps/web/src/components/preview/PreviewView.tsx
+6
@@ -895,6 +895,12 @@ export function PreviewView({
895 case "refresh":
896 handleRefresh();
897 return;
898 + case "back":
899 + handleBack();
900 + return;
901 + case "forward":
902 + handleForward();
903 + return;
904 case "focus-url":
905 urlInputRef.current?.focus();
906 return;
apps/web/src/components/preview/previewActionBus.ts
+2
@@ -1,6 +1,8 @@
1 export type PreviewAction =
2 | "toggle-panel"
3 | "refresh"
4 + | "back"
5 + | "forward"
6 | "focus-url"
7 | "zoom-in"
8 | "zoom-out"
apps/web/src/components/preview/thumbButtons.ts new
+19
@@ -0,0 +1,19 @@
1 +import type { MouseEvent as ReactMouseEvent } from "react";
2 +
3 +const isThumbButton = (event: ReactMouseEvent) => event.button === 3 || event.button === 4;
4 +
5 +// A thumb press would otherwise focus the URL bar, which then stops tracking the page.
6 +export function preventThumbButtonFocus(event: ReactMouseEvent) {
7 + if (isThumbButton(event)) event.preventDefault();
8 +}
9 +
10 +// Chromium runs app-router history on a thumb-button mouseup unless it is cancelled.
11 +// Page content that already stepped its own history cancels it first.
12 +export function takeThumbButtonNavigation(
13 + event: ReactMouseEvent,
14 + navigate: ((direction: "back" | "forward") => void) | undefined,
15 +) {
16 + if (!isThumbButton(event) || event.defaultPrevented) return;
17 + event.preventDefault();
18 + navigate?.(event.button === 3 ? "back" : "forward");
19 +}
apps/web/src/components/ui/input-group.tsx
+1
@@ -93,6 +93,7 @@ function InputGroupAddon({
93 data-align={align}
94 data-slot="input-group-addon"
95 onMouseDown={(e) => {
96 + if (e.button !== 0) return;
97 const target = e.target as HTMLElement;
98 const isInteractive = target.closest(
99 "button, a, input, select, textarea, [role='button'], [role='combobox'], [role='listbox'], [data-slot='select-trigger']",
apps/web/src/contextMenuFallback.keyboard.browser.test.ts
+12
@@ -104,3 +104,15 @@ it("closes without taking focus back when focus moves elsewhere", async () => {
104 await expect(result).resolves.toBeNull();
105 expect(document.activeElement).toBe(destination);
106 });
107 +
108 +it("takes thumb Back and Forward presses so the app router stays put", () => {
109 + using _fixture = setup();
110 + void showContextMenuFallback(items);
111 + for (const button of [3, 4]) {
112 + const event = new MouseEvent("mouseup", { button, bubbles: true, cancelable: true });
113 + document.activeElement!.dispatchEvent(event);
114 + // Chromium runs history back/forward on a thumb-button mouseup nobody cancelled.
115 + expect(event.defaultPrevented).toBe(true);
116 + }
117 + expect(isContextMenuOpen()).toBe(true);
118 +});
apps/web/src/contextMenuFallback.ts
+7
@@ -586,6 +586,13 @@ export function showContextMenuFallback<T extends string>(
586 menu.addEventListener("mouseenter", () => {
587 closeMenusFromLevel(level + 1);
588 });
589 + // Like a native menu, take thumb Back/Forward presses instead of letting Chromium
590 + // run the app router's history underneath.
591 + const swallowThumbButton = (event: MouseEvent) => {
592 + if (event.button === 3 || event.button === 4) event.preventDefault();
593 + };
594 + menu.addEventListener("mousedown", swallowThumbButton);
595 + menu.addEventListener("mouseup", swallowThumbButton);
596
597 document.body.appendChild(menu);
598 menuStack[level] = menu;