From 17d21d3a4545d52ce389d7bfa69109daf98dafd1 Mon Sep 17 00:00:00 2001 From: Etan Joseph Heyman Date: Sat, 31 Oct 2026 12:27:19 +0200 Subject: [PATCH 1/3] fix(web): horizontal scrolling inside diff and file panes no longer switches threads The history swipe guard walked event.target and its parents to find a horizontal scroller. Wheel events from inside a shadow root are retargeted to the shadow host, so scrollers in the diff and file viewers were missed and a sideways scroll there could navigate thread history instead. The guard now walks the event's composed path, which includes elements inside open shadow roots. Panels without horizontal overflow, and a fresh swipe at a scroller's edge, still navigate as before. Co-Authored-By: Claude Opus 5.5 --- .../HistorySwipeNavigation.browser.test.tsx | 37 +++++++++++++++++++ .../src/components/HistorySwipeNavigation.tsx | 23 ++++++------ 2 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 apps/web/src/components/HistorySwipeNavigation.browser.test.tsx diff --git a/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx b/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx new file mode 100644 index 0000000000000..dfa374483900f --- /dev/null +++ b/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx @@ -0,0 +1,37 @@ +import { describe, expect, it, vi } from "vite-plus/test"; + +import { render } from "../../test/render"; +import { HistorySwipeNavigation } from "./HistorySwipeNavigation"; + +const navigateHistory = vi.hoisted(() => vi.fn()); +vi.mock("../navigationHistory", () => ({ canNavigateHistory: () => true, navigateHistory })); + +function swipe(target: Element, deltaX: number) { + for (const delta of [deltaX, 0]) { + target.dispatchEvent(new WheelEvent("wheel", { deltaX: delta, bubbles: true, composed: true })); + } +} + +describe("HistorySwipeNavigation", () => { + it.each([ + ["scrolling left inside a shadow-root scroller keeps the thread", "shadow", 100, -130, false], + ["scrolling right inside a shadow-root scroller keeps the thread", "shadow", 100, 130, false], + ["scrolling left inside a scroller keeps the thread", "light", 100, -130, false], + ["swiping back at a shadow-root scroller's left edge navigates", "shadow", 0, -130, true], + ["swiping back over a panel without overflow navigates", "none", 0, -130, true], + ] as const)("%s", async (_name, scroller, scrollLeft, deltaX, navigates) => { + navigateHistory.mockReset(); + await using screen = await render(); + const panel = screen.container.appendChild(document.createElement("div")); + const root = scroller === "shadow" ? panel.attachShadow({ mode: "open" }) : panel; + const viewport = root.appendChild(document.createElement("div")); + viewport.style.cssText = `width: 200px; overflow-x: ${scroller === "none" ? "visible" : "auto"}`; + const content = viewport.appendChild(document.createElement("div")); + content.style.cssText = `height: 20px; width: ${scroller === "none" ? 100 : 1000}px`; + viewport.scrollLeft = scrollLeft; + + swipe(content, deltaX); + + expect(navigateHistory).toHaveBeenCalledTimes(navigates ? 1 : 0); + }); +}); diff --git a/apps/web/src/components/HistorySwipeNavigation.tsx b/apps/web/src/components/HistorySwipeNavigation.tsx index c020878b25363..f4bf2b398e9c7 100644 --- a/apps/web/src/components/HistorySwipeNavigation.tsx +++ b/apps/web/src/components/HistorySwipeNavigation.tsx @@ -11,7 +11,7 @@ const MOMENTUM_SAMPLE_SIZE = 5; type SwipeBounds = { left: number; top: number; width: number; height: number }; type SwipeGesture = - | { kind: "pending"; target: EventTarget | null; y: number; sumX: number; sumY: number } + | { kind: "pending"; path: EventTarget[]; y: number; sumX: number; sumY: number } | { kind: "tracking"; direction: HistoryDirection; @@ -37,13 +37,10 @@ function readMainContentBounds(): SwipeBounds { return { left, top, width, height }; } -function canScrollHorizontally(target: EventTarget | null, deltaX: number): boolean { - for ( - let element = target instanceof Element ? target : null; - element; - element = element.parentElement - ) { - if (element.scrollWidth <= element.clientWidth) continue; +// `event.target` stops at a shadow host; the composed path also reaches scrollers inside it. +function canScrollHorizontally(path: readonly EventTarget[], deltaX: number): boolean { + for (const element of path) { + if (!(element instanceof Element) || element.scrollWidth <= element.clientWidth) continue; const { overflowX } = getComputedStyle(element); if (overflowX !== "auto" && overflowX !== "scroll") continue; const canScroll = @@ -58,10 +55,12 @@ function canScrollHorizontally(target: EventTarget | null, deltaX: number): bool function lockSwipeAxis( pending: Extract, ): Exclude { - const { target, sumX, sumY } = pending; + const { path, sumX, sumY } = pending; if (Math.abs(sumX) <= Math.abs(sumY)) return { kind: "ignored" }; - if (target instanceof Element && target.closest('[role="dialog"]')) return { kind: "ignored" }; - if (canScrollHorizontally(target, sumX)) return { kind: "ignored" }; + if (path.some((node) => node instanceof Element && node.matches('[role="dialog"]'))) { + return { kind: "ignored" }; + } + if (canScrollHorizontally(path, sumX)) return { kind: "ignored" }; const direction = sumX < 0 ? "back" : "forward"; if (!canNavigateHistory(direction)) return { kind: "ignored" }; return { @@ -119,7 +118,7 @@ export function HistorySwipeNavigation() { gesture = event.ctrlKey || event.deltaMode !== WheelEvent.DOM_DELTA_PIXEL ? { kind: "ignored" } - : { kind: "pending", target: event.target, y: event.clientY, sumX: 0, sumY: 0 }; + : { kind: "pending", path: event.composedPath(), y: event.clientY, sumX: 0, sumY: 0 }; } if (gesture.kind === "ignored") return; if (gesture.kind === "pending") { From 4d90f20f85c51c3502ac6c84d4dbaab9f3872983 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Sat, 31 Oct 2026 22:52:35 +0000 Subject: [PATCH 2/3] fix(web): refresh swipe path when locking the gesture axis --- .../HistorySwipeNavigation.browser.test.tsx | 19 +++++++++++++++++-- .../src/components/HistorySwipeNavigation.tsx | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx b/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx index dfa374483900f..5b32f83fb7cfa 100644 --- a/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx +++ b/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx @@ -16,6 +16,13 @@ describe("HistorySwipeNavigation", () => { it.each([ ["scrolling left inside a shadow-root scroller keeps the thread", "shadow", 100, -130, false], ["scrolling right inside a shadow-root scroller keeps the thread", "shadow", 100, 130, false], + [ + "scrolling after a shadow scroller remount keeps the thread", + "shadow-remount", + 100, + 130, + false, + ], ["scrolling left inside a scroller keeps the thread", "light", 100, -130, false], ["swiping back at a shadow-root scroller's left edge navigates", "shadow", 0, -130, true], ["swiping back over a panel without overflow navigates", "none", 0, -130, true], @@ -23,14 +30,22 @@ describe("HistorySwipeNavigation", () => { navigateHistory.mockReset(); await using screen = await render(); const panel = screen.container.appendChild(document.createElement("div")); - const root = scroller === "shadow" ? panel.attachShadow({ mode: "open" }) : panel; + const root = scroller.startsWith("shadow") ? panel.attachShadow({ mode: "open" }) : panel; const viewport = root.appendChild(document.createElement("div")); viewport.style.cssText = `width: 200px; overflow-x: ${scroller === "none" ? "visible" : "auto"}`; const content = viewport.appendChild(document.createElement("div")); content.style.cssText = `height: 20px; width: ${scroller === "none" ? 100 : 1000}px`; viewport.scrollLeft = scrollLeft; - swipe(content, deltaX); + if (scroller === "shadow-remount") { + content.dispatchEvent(new WheelEvent("wheel", { deltaX: 1, bubbles: true, composed: true })); + const replacement = viewport.cloneNode(true) as HTMLDivElement; + viewport.replaceWith(replacement); + replacement.scrollLeft = scrollLeft; + swipe(replacement, deltaX); + } else { + swipe(content, deltaX); + } expect(navigateHistory).toHaveBeenCalledTimes(navigates ? 1 : 0); }); diff --git a/apps/web/src/components/HistorySwipeNavigation.tsx b/apps/web/src/components/HistorySwipeNavigation.tsx index f4bf2b398e9c7..f0ab2e968d0f0 100644 --- a/apps/web/src/components/HistorySwipeNavigation.tsx +++ b/apps/web/src/components/HistorySwipeNavigation.tsx @@ -125,7 +125,7 @@ export function HistorySwipeNavigation() { gesture.sumX += event.deltaX; gesture.sumY += event.deltaY; if (Math.abs(gesture.sumX) + Math.abs(gesture.sumY) < SWIPE_AXIS_LOCK_DISTANCE) return; - gesture = lockSwipeAxis(gesture); + gesture = lockSwipeAxis({ ...gesture, path: event.composedPath() }); if (gesture.kind === "ignored") return; } else { const delta = gesture.direction === "back" ? -event.deltaX : event.deltaX; From be63dd2c59ffbbed720a91a5c7b9bfe54e41db04 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Sat, 31 Oct 2026 23:12:30 +0000 Subject: [PATCH 3/3] fix(web): preserve the starting dialog guard during swipes --- .../HistorySwipeNavigation.browser.test.tsx | 13 +++++++++++-- apps/web/src/components/HistorySwipeNavigation.tsx | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx b/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx index 5b32f83fb7cfa..b2e6fcaaaf402 100644 --- a/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx +++ b/apps/web/src/components/HistorySwipeNavigation.browser.test.tsx @@ -26,17 +26,26 @@ describe("HistorySwipeNavigation", () => { ["scrolling left inside a scroller keeps the thread", "light", 100, -130, false], ["swiping back at a shadow-root scroller's left edge navigates", "shadow", 0, -130, true], ["swiping back over a panel without overflow navigates", "none", 0, -130, true], + ["a swipe that started in a closed dialog keeps the thread", "closed-dialog", 0, -130, false], ] as const)("%s", async (_name, scroller, scrollLeft, deltaX, navigates) => { navigateHistory.mockReset(); await using screen = await render(); const panel = screen.container.appendChild(document.createElement("div")); const root = scroller.startsWith("shadow") ? panel.attachShadow({ mode: "open" }) : panel; const viewport = root.appendChild(document.createElement("div")); - viewport.style.cssText = `width: 200px; overflow-x: ${scroller === "none" ? "visible" : "auto"}`; + const noOverflow = scroller === "none" || scroller === "closed-dialog"; + viewport.style.cssText = `width: 200px; overflow-x: ${noOverflow ? "visible" : "auto"}`; const content = viewport.appendChild(document.createElement("div")); - content.style.cssText = `height: 20px; width: ${scroller === "none" ? 100 : 1000}px`; + content.style.cssText = `height: 20px; width: ${noOverflow ? 100 : 1000}px`; viewport.scrollLeft = scrollLeft; + if (scroller === "closed-dialog") { + panel.setAttribute("role", "dialog"); + content.dispatchEvent(new WheelEvent("wheel", { deltaX: -1, bubbles: true, composed: true })); + panel.remove(); + screen.container.appendChild(viewport); + } + if (scroller === "shadow-remount") { content.dispatchEvent(new WheelEvent("wheel", { deltaX: 1, bubbles: true, composed: true })); const replacement = viewport.cloneNode(true) as HTMLDivElement; diff --git a/apps/web/src/components/HistorySwipeNavigation.tsx b/apps/web/src/components/HistorySwipeNavigation.tsx index f0ab2e968d0f0..767b4285c696f 100644 --- a/apps/web/src/components/HistorySwipeNavigation.tsx +++ b/apps/web/src/components/HistorySwipeNavigation.tsx @@ -125,7 +125,7 @@ export function HistorySwipeNavigation() { gesture.sumX += event.deltaX; gesture.sumY += event.deltaY; if (Math.abs(gesture.sumX) + Math.abs(gesture.sumY) < SWIPE_AXIS_LOCK_DISTANCE) return; - gesture = lockSwipeAxis({ ...gesture, path: event.composedPath() }); + gesture = lockSwipeAxis({ ...gesture, path: [...gesture.path, ...event.composedPath()] }); if (gesture.kind === "ignored") return; } else { const delta = gesture.direction === "back" ? -event.deltaX : event.deltaX;