Skip to content

Commit 21015dd

Browse files
PR Batch Testerclaude
andcommitted
fix(desktop): content appearing after a history release can still claim the swipe
A history swipe released by a zero wheel became a bare ignored gesture, so a wheel on content that appeared under the still pointer before the native end was never classified, and the next swipe at that position navigated again. A released swipe now keeps its wheel target, and tracking and released gestures share the new-target check. Zero-delta wheels still never claim, and gestures that were never a swipe (zoom, line-mode, vertical, dialog) stay unclassified. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9220955 commit 21015dd

2 files changed

Lines changed: 45 additions & 15 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,30 @@ describe("HistorySwipeNavigation", () => {
140140
[[60, "remove"], [70]],
141141
"forward",
142142
],
143+
[
144+
"content appearing after history release before its native end",
145+
"none",
146+
0,
147+
[["begin"], [130], [0], ["show-scroller"], [7, "remove"], ["end"], ["begin"], [130], ["end"]],
148+
"forward",
149+
],
150+
[
151+
"zero-delta contact on content appearing after history release",
152+
"none",
153+
0,
154+
[
155+
["begin"],
156+
[130],
157+
[0],
158+
["show-scroller"],
159+
[0, "remove"],
160+
["end"],
161+
["begin"],
162+
[-130],
163+
["end"],
164+
],
165+
"both",
166+
],
143167
[
144168
"the next gesture's first wheel arriving before the previous end, then scroller removal",
145169
"shadow",

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ type SwipeGesture =
2121
bounds: SwipeBounds;
2222
origin: EventTarget | undefined;
2323
}
24-
// Not a swipe, or one already decided: the rest of its events are ignored.
25-
| { kind: "ignored" };
24+
// Not a swipe: the rest of its events are ignored.
25+
| { kind: "ignored" }
26+
// A decided history swipe. Its momentum is ignored, but content can still claim it.
27+
| { kind: "released"; origin: EventTarget | undefined };
2628
type SwipeIndicatorState = {
2729
direction: HistoryDirection;
2830
progress: number;
@@ -53,7 +55,7 @@ function isInHorizontalScroller(path: readonly EventTarget[]): boolean {
5355
function lockSwipeAxis(
5456
pending: Extract<SwipeGesture, { kind: "pending" }>,
5557
origin: EventTarget | undefined,
56-
): Exclude<SwipeGesture, { kind: "pending" }> {
58+
): Extract<SwipeGesture, { kind: "ignored" | "tracking" }> {
5759
const { path, sumX, sumY } = pending;
5860
if (Math.abs(sumX) <= Math.abs(sumY)) return { kind: "ignored" };
5961
if (path.some((node) => node instanceof Element && node.matches('[role="dialog"]'))) {
@@ -123,19 +125,17 @@ export function HistorySwipeNavigation() {
123125
if (!["Alt", "Control", "Meta", "Shift"].includes(event.key)) resetContext();
124126
};
125127
// The fingers lifted: navigate if the swipe went far enough, then ignore its momentum.
126-
const release = () => {
127-
if (gesture?.kind === "tracking" && gesture.distance >= SWIPE_TRIGGER_DISTANCE) {
128-
navigateHistory(gesture.direction);
129-
}
130-
gesture = { kind: "ignored" };
128+
const release = (swipe: Extract<SwipeGesture, { kind: "tracking" }>) => {
129+
if (swipe.distance >= SWIPE_TRIGGER_DISTANCE) navigateHistory(swipe.direction);
130+
gesture = { kind: "released", origin: swipe.origin };
131131
hideIndicator();
132132
};
133133
// Chromium brackets each trackpad scroll, momentum included, with these.
134134
const unsubscribeScrollBegin = window.desktopBridge?.onTrackpadScrollBegin(() => {
135-
if (gesture?.kind === "ignored") gesture = null;
135+
if (gesture?.kind === "ignored" || gesture?.kind === "released") gesture = null;
136136
});
137137
const unsubscribeScrollEnd = window.desktopBridge?.onTrackpadScrollEnd(() => {
138-
if (gesture?.kind === "tracking") release();
138+
if (gesture?.kind === "tracking") release(gesture);
139139
gesture = null;
140140
});
141141
const onWheel = (event: WheelEvent) => {
@@ -152,16 +152,22 @@ export function HistorySwipeNavigation() {
152152
: { kind: "pending", path: event.composedPath(), y: event.clientY, sumX: 0, sumY: 0 };
153153
}
154154
if (gesture.kind === "ignored") return;
155-
if (gesture.kind === "tracking") {
156-
const delta = gesture.direction === "back" ? -event.deltaX : event.deltaX;
157-
if (event.deltaX === 0 && event.deltaY === 0) return release();
158-
// Content can appear under a still pointer while a stale trailing wheel is tracking.
155+
if (gesture.kind !== "pending") {
156+
if (event.deltaX === 0 && event.deltaY === 0) {
157+
if (gesture.kind === "tracking") release(gesture);
158+
return;
159+
}
160+
// Content can appear under a still pointer before a history swipe's native end.
159161
// Only a new wheel target is classified, so overflow gained mid-swipe stays history.
160162
const path = event.composedPath();
161163
if (path[0] !== gesture.origin) {
162164
if (isInHorizontalScroller(path)) return claimContent();
163165
gesture.origin = path[0];
164166
}
167+
}
168+
if (gesture.kind === "released") return;
169+
if (gesture.kind === "tracking") {
170+
const delta = gesture.direction === "back" ? -event.deltaX : event.deltaX;
165171
const { direction, distance, y } = gesture;
166172
// Past its start the swipe picks a direction again: a stale trailing wheel may
167173
// have opened it, and the next swipe's begin can arrive after its first wheels.
@@ -176,7 +182,7 @@ export function HistorySwipeNavigation() {
176182
hideIndicator();
177183
} else {
178184
gesture.deltas = [...gesture.deltas.slice(1 - MOMENTUM_SAMPLE_SIZE), delta];
179-
if (isMomentumTail(gesture.deltas)) return release();
185+
if (isMomentumTail(gesture.deltas)) return release(gesture);
180186
gesture.distance = Math.max(0, distance + delta);
181187
}
182188
}

0 commit comments

Comments
 (0)