Skip to content

Commit b2f170f

Browse files
fix(web): thumb presses over the hosted browser toolbar step the tab, not the app router
The desktop Browser's hosted webview wrapper (device-size toolbar and padding) is a fixed element rendered outside the right panel shell, so the panel's thumb-button handling never saw those presses and Chromium ran app-router history instead. The wrapper now cancels thumb presses and steps its own runtime tab's history, sharing the panel's handler. AI-assisted; verified with the tests and tools listed above.
1 parent 801d339 commit b2f170f

3 files changed

Lines changed: 38 additions & 16 deletions

File tree

‎apps/web/src/browser/HostedBrowserWebview.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { useShallow } from "zustand/react/shallow";
77
import { useEffect, useEffectEvent, useRef, useState } from "react";
88

99
import { previewBridge } from "~/components/preview/previewBridge";
10+
import {
11+
preventThumbButtonFocus,
12+
takeThumbButtonNavigation,
13+
} from "~/components/preview/thumbButtons";
1014
import { usePreviewBridge } from "~/components/preview/usePreviewBridge";
1115
import { useClientSettingsHydrated } from "~/hooks/useSettings";
1216
import { cn, isMacPlatform } from "~/lib/utils";
@@ -302,6 +306,12 @@ export function HostedBrowserWebview(props: {
302306

303307
if (!clientSettingsHydrated || !config) return null;
304308

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+
305315
const renderingActive = active || backgroundActivity || pictureInPicture || recordingActive;
306316
const wrapperStyle = resolveHostedBrowserWebviewWrapperStyle({
307317
active,
@@ -320,6 +330,8 @@ export function HostedBrowserWebview(props: {
320330
className="fixed overflow-hidden bg-muted/35"
321331
style={{ ...wrapperStyle, overscrollBehavior: "contain" }}
322332
onScroll={syncContentPresentation}
333+
onMouseDown={preventThumbButtonFocus}
334+
onMouseUp={(event) => takeThumbButtonNavigation(event, navigateThumb)}
323335
data-preview-rendering={renderingActive ? "active" : "suspended"}
324336
data-preview-viewport={runtimeTabId}
325337
>

‎apps/web/src/components/RightPanelTabs.tsx‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ import { PreviewPanelShell, type PreviewPanelMode } from "./preview/PreviewPanel
100100
import { FaviconImage } from "./preview/PreviewFaviconIcon";
101101
import { previewBridge } from "./preview/previewBridge";
102102
import { dispatchPreviewAction } from "./preview/previewActionBus";
103+
import { preventThumbButtonFocus, takeThumbButtonNavigation } from "./preview/thumbButtons";
103104
import { PierreEntryIcon } from "./chat/PierreEntryIcon";
104105
import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
105106
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
@@ -866,21 +867,6 @@ function preventTabMiddleButtonDefault(event: ReactMouseEvent) {
866867
event.preventDefault();
867868
}
868869

869-
const isThumbButton = (event: ReactMouseEvent) => event.button === 3 || event.button === 4;
870-
871-
// A thumb press would otherwise focus the URL bar, which then stops tracking the page.
872-
function preventThumbButtonFocus(event: ReactMouseEvent) {
873-
if (isThumbButton(event)) event.preventDefault();
874-
}
875-
876-
// Chromium runs app-router history on a thumb-button mouseup unless it is cancelled.
877-
// Page content that already stepped its own history cancels it first.
878-
function routeThumbButtonToSurface(event: ReactMouseEvent, surface: RightPanelSurface | undefined) {
879-
if (!isThumbButton(event) || event.defaultPrevented) return;
880-
event.preventDefault();
881-
if (surface?.kind === "preview") dispatchPreviewAction(event.button === 3 ? "back" : "forward");
882-
}
883-
884870
// Stable handlers and per-tab values let the compiler reuse tabs across parent renders.
885871
function RightPanelTab(
886872
props: RightPanelTabHandlers & {
@@ -1347,7 +1333,12 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
13471333
{...(props.defaultWidth !== undefined ? { defaultWidth: props.defaultWidth } : {})}
13481334
{...(props.inlineSize ? { inlineSize: props.inlineSize } : {})}
13491335
onMouseDown={preventThumbButtonFocus}
1350-
onMouseUp={(event) => routeThumbButtonToSurface(event, focusedSurface)}
1336+
onMouseUp={(event) =>
1337+
takeThumbButtonNavigation(
1338+
event,
1339+
focusedSurface?.kind === "preview" ? dispatchPreviewAction : undefined,
1340+
)
1341+
}
13511342
>
13521343
<div
13531344
className={cn(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

0 commit comments

Comments
 (0)