Skip to content

Keep mobile sidebar drags from sticking or fighting the drawer - #6469

Merged
ymichael merged 2 commits into
mainfrom
bb/fix-mobile-sidebar-drag-issues-thr_pa3yz7xjrk
Oct 28, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/fix-mobile-sidebar-drag-issues-thr_pa3yz7xjrk

Conversation

@ymichael

@ymichael ymichael commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Since #4329 replaced dnd-kit's TouchSensor with the custom long-press SidebarTouchSensor, the sensor listened for touchmove/touchend/touchcancel on document. Touch events keep targeting the element where the touch started. If that row remounts mid-drag, the remaining events go to a detached node and never bubble to document. dnd-kit attaches these listeners to the event target for exactly this reason. A remount happens, for example, when an agent spawns a child thread under the held row, or when another client pins it. The drag then never ends:

  • the drag chip stays on screen, including over the thread view once the drawer closes;
  • the next tap anywhere ends the stale drag as a drop, so it doesn't navigate and instead moves or nests the thread wherever the tap landed.

A second path leaves a row stuck as "being dragged" even when it stays on the page. A long-press released with a quick slide past 12 px fires the sensor's onStart and onEnd in the same task. dnd-kit records the active drag in sensorContext only in a layout effect. Its end handler therefore sees no active drag and skips onDragEnd/onDragCancel, but our onDragStart has already run. The row stays at opacity: 0.35, pointerEvents: "none" and ignores taps until a reload. This was the cause of the row stuck after long-press, Archive and Unarchive, diagnosed in a separate bb thread.

Two gesture conflicts also made row drags feel finicky:

  • The drawer's horizontal dismiss gesture (useHorizontalDismissDrag, restored in Restore mobile sidebar swipe dismissal #2805) never checked whether another handler had claimed the touch. A sideways row drag therefore slid the sidebar closed under the chip and dismissed it on release.
  • Between arming (a 6 px hold tolerance) and starting the drag (12 px of movement), the sensor did not cancel touchmoves, so native list scrolling could start alongside the drag.

What changed

  • plugins/thread-list/app/dnd/sidebarTouchSensor.ts: attach the move/end/cancel listeners to the touch target instead of document. Once a row is armed, preventDefault every touchmove, not only after the drag starts. Wrap onStart in flushSync so dnd-kit commits the active drag before a release in the same task can arrive.
  • apps/app/src/components/ui/use-horizontal-dismiss-drag.ts: before a dismiss drag begins, a defaultPrevented touchmove abandons the session, the same way a native text selection already does. This affects the mobile sidebar and the compact secondary panel shelf.

How you verified

  • New tests that fail before and pass after:
    • sidebarTouchSensor.test.tsx: the drag ends when the touched row remounts mid-drag, and a later touch is not hijacked;
    • sidebarTouchSensor.test.tsx: an armed hold claims touchmoves;
    • sidebarTouchSensor.test.tsx: a drag whose move and release are dispatched in the same task, outside act, still reports onDragEnd;
    • sidebar.test.tsx: the drawer stays open when a row gesture claims the swipe's touchmoves.
  • pnpm exec turbo run typecheck test lint --filter=bb-plugin-thread-list (482 tests), plus pnpm exec turbo run typecheck lint --filter=@bb/app and the @bb/app tests under src/components/{ui,sidebar,secondary-panel} (1352 tests).
  • Manual QA on pnpm dev in headless Chrome at 390×844 with touch emulation and CDP Input.dispatchTouchEvent:
    • before the fix, pinning the held thread through the API mid-drag left the chip stuck; the next tap on another thread did not navigate and nested the dragged thread under a different one;
    • after the fix, the same sequence clears the chip on release, and the next tap navigates and closes the drawer;
    • before the fix, a long-press then sideways drag closed the drawer; after it, the drawer stays open.
  • The flushSync half was verified separately in Chromium on an isolated dev build. A hold, quick slide and release previously left the row stuck; with the fix, the drag ends about 20 ms after release. That build had the listener change and flushSync but not the scroll or drawer changes.
  • Not tested on iOS Safari or the iOS app.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits October 28, 2026 12:52
The thread list's touch sensor listened for touchmove/touchend on the
document. When the held row remounted mid-drag (an agent spawning a child
under it, a pin from another client), the touch's remaining events went to
the detached element and never bubbled, so the drag overlay stayed on
screen and the next tap anywhere ended the stale drag as a drop. Listen on
the touch target, as dnd-kit's TouchSensor does.

Once a row is armed, claim every touchmove so native scrolling cannot start
alongside the drag, and have the drawer's horizontal dismiss gesture skip
moves another handler already claimed, so a sideways row drag no longer
slides the sidebar closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A long-press released with a quick slide fires the sensor's onStart and
onEnd in the same task. dnd-kit only records the active drag in a layout
effect, so its end handler saw no active drag and skipped onDragEnd while
our onDragStart had already run, leaving the row dimmed and untappable.
Flush the start synchronously so the end is always reported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 4a9abe3 into main Oct 28, 2026
45 checks passed
@ymichael
ymichael deleted the bb/fix-mobile-sidebar-drag-issues-thr_pa3yz7xjrk branch October 28, 2026 20:23
ymichael added a commit that referenced this pull request Nov 16, 2026
…mounts (#7600)

## Human comments

## What was wrong

On compact screens, swiping the sidebar or the right panel sometimes
left it stuck partway until the next swipe. This happened when the
timeline re-rendered during the swipe. Touch events always go to the
element the touch started on, even after it has been removed from the
page, and a removed element no longer passes them on to `window`. The
swipe code listened for the rest of the gesture (`touchmove`,
`touchend`, and the pointer equivalents) only on `window`. So when a
re-render remounted the touched element, the swipe stopped receiving
events and never finished. `recoverInterruptedMobileSwipe` reset it on
the next touch, which is why another swipe got it unstuck. #6469 fixed
the same problem for sidebar row drags.

## What changed

- `gesture-dom.ts`: a new `listenToGesture(origin, type, listener,
options)` listens on both `window` and the element the gesture started
on, and calls the listener once even when the same event reaches both.
- `sidebar.tsx`: the swipe that opens the sidebar uses it for both touch
and pointer input.
- `use-horizontal-dismiss-drag.ts`: uses it for both touch and pointer
input. This covers dragging the sidebar drawer closed and both
right-panel drags (open and close).

## How you verified

- New tests: `sidebar.test.tsx` covers a touch and a pointer swipe whose
touched element remounts mid-drag. `CompactSecondaryPanelShelf.test.tsx`
covers opening and closing the right panel the same way. All four fail
without the source change and pass with it.
- `pnpm exec turbo run test --filter=@bb/app -- src/components/ui
src/components/secondary-panel src/components/sidebar` passed: 1379
tests in 125 files.
- `pnpm exec turbo run typecheck lint --filter=@bb/app` passed.
- Manual check on a `pnpm start:worktree` build, comparing it with
`main`'s app bundle on the same server and data. I used headless Chrome
as a touch phone and sent real touches over the Chrome DevTools
Protocol. Partway through each swipe I swapped the touched element for a
copy, which is what a remount does. Results after lifting the finger:

| Case | Sizes | `main` | This branch |
|---|---|---|---|
| Swipe right to open the sidebar | 390×844, 360×780, 744×1133 | stuck
110px across | opens fully |
| Swipe left to open the right panel | same three | stuck at −90px,
panel stays closed | opens fully |
| Drag a sidebar row left to close the sidebar | 390×844 | stuck 255px
across | closes |
| Drag right inside the right panel to close it | 390×844 | stays open
with a −270px offset on the page behind | closes |
| Normal swipe, nothing remounted (control) | 390×844 | opens fully | —
|

- Not tested: a physical device, iOS Simulator Safari, and the native
mobile shell.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant