The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): don't let webview guests swallow drag gestures
Brooklyn Nicholson7267adafdf54
diff --git a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx b/apps/desktop/src/app/chat/right-rail/preview-pane.tsxindex cc088bf2e18..681b1463b72 100644--- a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx+++ b/apps/desktop/src/app/chat/right-rail/preview-pane.tsx@@ -5,6 +5,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { Tip } from '@/components/ui/tooltip'import { type Translations, useI18n } from '@/i18n'import { isDesktopFsRemoteMode } from '@/lib/desktop-fs'+import { guardGuestPointers } from '@/lib/guest-pointer-guard'import { openPreviewTargetInBrowser, remoteHtmlPreviewDocument } from '@/lib/local-preview'import { rafCoalesce } from '@/lib/raf-coalesce'import { cn } from '@/lib/utils'@@ -187,6 +188,8 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =document.body.style.cursor = 'row-resize'document.body.style.userSelect = 'none'+ // The webview above the console must not swallow the gesture.+ const releaseGuests = guardGuestPointers()// pointermove outpaces 60fps and each setHeight reflows the webview +// console split, so coalesce to one apply per frame (commits on cleanup).@@ -207,6 +210,7 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =active = falseresize.finish()+ releaseGuests()document.body.style.cursor = previousCursordocument.body.style.userSelect = previousUserSelecthandle.releasePointerCapture?.(pointerId)diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/drag-session.ts b/apps/desktop/src/components/pane-shell/tree/renderer/drag-session.tsindex 6e479c67952..826f15d4b91 100644--- a/apps/desktop/src/components/pane-shell/tree/renderer/drag-session.ts+++ b/apps/desktop/src/components/pane-shell/tree/renderer/drag-session.ts@@ -32,6 +32,7 @@ import type { PointerEvent as ReactPointerEvent } from 'react'import { createDragGhost, type DragGhost } from '@/lib/drag-ghost'import { ESCAPE_PRIORITY, pushEscapeLayer } from '@/lib/escape-layers'+import { guardGuestPointers } from '@/lib/guest-pointer-guard'import { reorderCommitHaptic, reorderStepHaptic } from '@/lib/reorder'import type { DropPosition } from '../model'@@ -235,6 +236,7 @@ export function startDragSession(e: ReactPointerEvent<HTMLElement>, spec: DragSeconst restoreSelect = document.body.style.userSelectlet engaged = falselet releaseEscapeLayer: (() => void) | null = null+ let releaseGuests: (() => void) | null = nulllet ghost: DragGhost | null = nulllet cursor: string | null = null// rAF-coalesced move processing: the raw handler only records the latest@@ -275,6 +277,9 @@ export function startDragSession(e: ReactPointerEvent<HTMLElement>, spec: DragSesetCursor('grabbing')document.body.style.userSelect = 'none'+ // Webview/iframe guests hit-test in their own process — dragging a tab+ // across the in-app browser would go silent without this.+ releaseGuests = guardGuestPointers()// While dragging, Esc belongs to the drag ALONE — lower layers (edit// mode, overlays) must not also fire on the same press.releaseEscapeLayer = pushEscapeLayer(ESCAPE_PRIORITY.drag)@@ -339,6 +344,8 @@ export function startDragSession(e: ReactPointerEvent<HTMLElement>, spec: DragSeghost = nullreleaseEscapeLayer?.()releaseEscapeLayer = null+ releaseGuests?.()+ releaseGuests = nulltry {handle.releasePointerCapture?.(pointerId)diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-split.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-split.tsxindex 21ca5ecd0a4..dd59afb3fab 100644--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-split.tsx+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-split.tsx@@ -11,6 +11,7 @@ import { type PointerEvent as ReactPointerEvent, useCallback, useMemo, useRef, uimport { beginSashDrag, endSashDrag } from '@/components/pane-shell/geometry'import { useContributions } from '@/contrib/react/use-contributions'+import { guardGuestPointers } from '@/lib/guest-pointer-guard'import { rafCoalesce } from '@/lib/raf-coalesce'import { cn } from '@/lib/utils'import { $paneStates, type PaneStateSnapshot, setPaneHeightOverride, setPaneWidthOverride } from '@/store/panes'@@ -258,6 +259,10 @@ export function TreeSplit({ node, root, rootRow }: { node: SplitNode; root?: boodocument.body.style.cursor = horizontal ? 'col-resize' : 'row-resize'document.body.style.userSelect = 'none'+ // Webview/iframe guests must not swallow the gesture — without this the+ // drag froze the moment the pointer entered the in-app browser, so the+ // seam could only shrink it a few px per press.+ const releaseGuests = guardGuestPointers()// Suppress :root geometry-var writes for the gesture (see geometry.ts —// each one restyles the whole document; they republish on release).beginSashDrag()@@ -323,13 +328,22 @@ export function TreeSplit({ node, root, rootRow }: { node: SplitNode; root?: booconst resize = rafCoalesce(previewShift)let lastShift: null | number = null+ let done = falseconst onMove = (ev: PointerEvent) => {lastShift = Math.max(lo, Math.min(hi, (horizontal ? ev.clientX : ev.clientY) - start))resize.push(lastShift)}+ // Ends through several racing paths (pointerup, pointercancel, window+ // blur, lostpointercapture — releasePointerCapture below fires the+ // latter re-entrantly), so it must run exactly once.const cleanup = () => {+ if (done) {+ return+ }++ done = trueresize.finish()if (lastShift !== null) {@@ -367,6 +381,7 @@ export function TreeSplit({ node, root, rootRow }: { node: SplitNode; root?: boo// Geometry vars re-enable AFTER the final store commit above, so the// release publishes exactly one fresh measurement.endSashDrag()+ releaseGuests()document.body.style.cursor = restoreCursordocument.body.style.userSelect = restoreSelect@@ -379,12 +394,16 @@ export function TreeSplit({ node, root, rootRow }: { node: SplitNode; root?: boowindow.removeEventListener('pointermove', onMove, true)window.removeEventListener('pointerup', cleanup, true)window.removeEventListener('pointercancel', cleanup, true)+ window.removeEventListener('blur', cleanup)+ handle.removeEventListener('lostpointercapture', cleanup)persistTree()}window.addEventListener('pointermove', onMove, true)window.addEventListener('pointerup', cleanup, true)window.addEventListener('pointercancel', cleanup, true)+ window.addEventListener('blur', cleanup)+ handle.addEventListener('lostpointercapture', cleanup)},// trackCtx is derived state rebuilt per render; the drag captures it once.// eslint-disable-next-line react-hooks/exhaustive-depsdiff --git a/apps/desktop/src/lib/guest-pointer-guard.ts b/apps/desktop/src/lib/guest-pointer-guard.tsnew file mode 100644index 00000000000..0b2d039dcb6--- /dev/null+++ b/apps/desktop/src/lib/guest-pointer-guard.ts@@ -0,0 +1,36 @@+/**+ * Electron <webview> guests (and iframes) hit-test in their own process, so a+ * pointer-capture drag in the embedder goes silent the moment the cursor+ * crosses one — a sash resize froze after a few pixels of travel into the+ * in-app browser, and only another press could continue it. While a drag is+ * live, make every guest surface transparent to hit-testing (see the+ * `guest-pointer-lock` rule in styles.css) so the window-level pointermove /+ * pointerup listeners keep receiving the gesture.+ */+let depth = 0++/** Suppress pointer events on webview/iframe guests until released. Depth-+ * counted so overlapping gestures compose; the returned release is+ * idempotent (drags end through several racing paths — pointerup, blur,+ * lostpointercapture). */+export function guardGuestPointers(): () => void {+ if (depth === 0) {+ document.body.classList.add('guest-pointer-lock')+ }++ depth += 1+ let released = false++ return () => {+ if (released) {+ return+ }++ released = true+ depth -= 1++ if (depth === 0) {+ document.body.classList.remove('guest-pointer-lock')+ }+ }+}diff --git a/apps/desktop/src/styles.css b/apps/desktop/src/styles.cssindex 75dec6eb678..a070fa623f6 100644--- a/apps/desktop/src/styles.css+++ b/apps/desktop/src/styles.css@@ -1099,6 +1099,13 @@ code {border-color: var(--dt-destructive);}+/* Drag in progress (sash resize, console resize, tab drag): webview/iframe+ guests hit-test in their own process and swallow the gesture the moment the+ pointer crosses them — see lib/guest-pointer-guard.ts. */+body.guest-pointer-lock :is(webview, iframe) {+ pointer-events: none;+}+@layer components {/* Chromium 121+ (Electron) prefers standard scrollbar-* over::-webkit-scrollbar and ignores the latter when both are set — platform