Skip to content

Commit 8b2c2fd

Browse files
fix(web): wheels after a trackpad gesture ends no longer start a swipe
Desktop forwards gestureScrollBegin/End over IPC, so a gesture's last wheel can reach the renderer after its end. With the tab strip at its left edge that straggler started a back swipe, left the indicator showing, and carried into the next gesture, which then navigated back from inside the strip. gestureScrollEnd now releases the gesture and leaves it ignored, so stragglers are dropped until the next gestureScrollBegin resets it. AI-assisted; verified with the tests and tools listed above.
1 parent 81a49c1 commit 8b2c2fd

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function HistorySwipeNavigation() {
9696
useEffect(() => {
9797
let gesture: SwipeGesture | null = null;
9898
const hideIndicator = () =>
99-
setSwipe((current) => (current === null ? null : { ...current, tracking: false }));
99+
setSwipe((current) => (current?.tracking ? { ...current, tracking: false } : current));
100100
// The fingers lifted: navigate if the swipe went far enough, then ignore its momentum.
101101
const release = () => {
102102
if (gesture?.kind === "tracking" && gesture.distance >= SWIPE_TRIGGER_DISTANCE) {
@@ -109,10 +109,8 @@ export function HistorySwipeNavigation() {
109109
const unsubscribeScrollBegin = window.desktopBridge?.onTrackpadScrollBegin(() => {
110110
if (gesture?.kind === "ignored") gesture = null;
111111
});
112-
const unsubscribeScrollEnd = window.desktopBridge?.onTrackpadScrollEnd(() => {
113-
if (gesture?.kind === "tracking") release();
114-
gesture = null;
115-
});
112+
// A gesture's last wheels can arrive after its end IPC; ignore them until the next begin.
113+
const unsubscribeScrollEnd = window.desktopBridge?.onTrackpadScrollEnd(release);
116114
const onWheel = (event: WheelEvent) => {
117115
if (gesture === null) {
118116
gesture =

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import "~/index.css";
33
import { describe, expect, it, vi } from "vite-plus/test";
44

55
import type { RightPanelSurface } from "~/rightPanelStore";
6-
import { render, stubGlobal } from "../../test/render";
6+
import { act, render, stubGlobal } from "../../test/render";
77
import { HistorySwipeNavigation } from "./HistorySwipeNavigation";
88
import { RightPanelTabs } from "./RightPanelTabs";
99

@@ -126,5 +126,15 @@ describe("RightPanelTabs", () => {
126126

127127
expect(viewport.scrollLeft).toBe(0);
128128
expect(navigateHistory).not.toHaveBeenCalled();
129+
130+
// Gesture events reach the renderer over IPC, so a wheel can land after its gesture's end.
131+
await act(() => {
132+
viewport.dispatchEvent(new WheelEvent("wheel", { deltaX: -10, bubbles: true }));
133+
});
134+
expect(screen.container.querySelector(".lucide-arrow-left")).toBeNull();
135+
viewport.scrollLeft = 120;
136+
scroll(viewport.querySelector("[data-active-tab]")!, [-10, -20, -30, ...momentum]);
137+
138+
expect(navigateHistory).not.toHaveBeenCalled();
129139
});
130140
});

0 commit comments

Comments
 (0)