Skip to content

fix(core): let the Bottom Sheet be dragged up from its scroll area on iOS - #5178

Merged
imdreamrunner merged 1 commit into
mainfrom
fix/bottom-sheet-ios-pointer-id-collision
Aug 18, 2026
Merged

imdreamrunner merged 1 commit into
mainfrom
fix/bottom-sheet-ios-pointer-id-collision

Conversation

@imdreamrunner

Copy link
Copy Markdown
Contributor

fix(core): let the Bottom Sheet be dragged up from its scroll area on iOS

The bug

With the sheet resting below its tallest detent, a pull up inside the
scrolling content
does nothing on a real device. The grab handle drags the
same sheet perfectly. Reported as "I can drag up using the little bar, but I
can't drag up using the scroll area."

Not a gating or geometry problem — the sheet does take the gesture, and then
loses it one event later.

Root cause: Touch.identifier and PointerEvent.pointerId are the same

number on iOS

The body's touch path drives the shared drag machinery by handing it a
pointer-shaped object built from a Touch. On WebKit the id it copies out of
touch.identifier names a live pointer — so the drag is keyed to a real
one, and the handlers that exist to protect a mouse drag fire against it.

Instrumented, one gesture on iOS 26.5 / Safari 26.5 (iPhone 17 Simulator),
@astryxdesign/[email protected], sheet at the 0.5 detent, content
parked at its end:

touchstart                      y=638  scrollTop=271/271
touchmove #1  -> armed-edge promotion, preventDefault, beginDrag
  gotpointercapture   pointerId=-1239851261   <- the Touch.identifier, exactly
  setPointerCapture   has=true
  beginDrag           startCoord=638
  lostpointercapture  pointerId=-1239851261  dragId=-1239851261  willCancel=TRUE
  cancelDrag                                  <- 0 ms after the drag began
touchmove #2..#50               drag gone; the sheet ignores the rest of the pull

beginDrag calls setPointerCapture(event.pointerId). Because that id is a
real pointer the capture succeeds; WebKit reclaims it immediately for its own
gesture handling; handleLostPointerCapture sees a matching id and cancels.
The promotion had already nulled touchDragRef, so nothing re-arms and the
remaining ~50 moves do nothing.

Why nothing caught this

  • Chromium keeps the two id spaces apart (small, separate sequences), so
    under DevTools touch emulation the synthetic id never matches a live pointer
    and no lostpointercapture ever arrives. Every scripted repro to date was
    Chromium.
  • The unit tests can't see it: makeTarget() stubs
    el.setPointerCapture = vi.fn(), so capture never happens and jsdom never
    fires the cancelling event.
  • The handle keeps working — it runs on real pointer events, which
    legitimately hold the capture.
  • The mid-gesture content-end handoff (fix(core): hand the Bottom Sheet the pull when its content runs out #5172) usually survives only by
    timing: it promotes after WebKit has already fired pointercancel +
    lostpointercapture for that finger at scroll commit, so there is no live
    capture left to lose. The armed-edge path promotes on the first move,
    while the pointer is still live, and loses the race every time.

The fix

Mark the pointer-shaped objects the touch path synthesises, and keep
real-pointer handling off the drags they start:

  • No capture for a touch drag. It is driven by touchmove on the scroller
    itself and never needed one.
  • lostpointercapture is ignored for such a drag — it is WebKit reclaiming
    its own pointer, not the drag losing its grip.
  • pointercancel / pointerup for that finger no longer end it. They
    arrive carrying the drag's own id; touchend is what finishes a touch drag.
    (Ending on pointercancel would settle the sheet mid-pull.)
  • A real pointermove for that finger no longer double-drives it.

Verification

New unit tests dispatch onLostPointerCapture and onPointerCancel with a
pointerId equal to the touch identifier — the collision, reproduced in jsdom.
Both fail on main (expected false to be true) and pass here, so CI holds
this without a device.

On an iPhone 17 Simulator (iOS 26.5), one continuous touch per case, sheet at
the 0.5 detent. Numbers are the scrolling body's height: 309 = mid detent,
395 = fully open. The "after" column is a build of this branch's source, not a
hand-patched bundle.

case before after
fresh touch at the content end, pull up 309 -> 309 (inert) 309 -> 395
scroll to the end mid-gesture, keep pulling (#5172) 309 -> 395 309 -> 395
top-edge pull-down in the body 395 -> 309 395 -> 309
ordinary mid-content scroll scrolls, sheet still unchanged
grab-handle drag works works

Only the reported case changes.

packages/core/src/BottomSheet suite 163/163; tsc --noEmit clean;
lint:strict 0 errors.

… iOS

Below the tallest detent, a pull up inside the sheet's content did nothing on a
real device while the grab handle worked fine.

iOS Safari raises PointerEvents for a finger under the SAME numeric id it puts
in `Touch.identifier`. The touch path builds its pointer-shaped event out of
that identifier, so the drag it starts is keyed to a live pointer: `beginDrag`
captures it, WebKit takes the capture straight back for its own gesture
handling, and the `lostpointercapture` that follows a millisecond later cancels
the drag one event after it began. Measured on iOS 26.5, one gesture:

  touchmove #1 -> promote, beginDrag
    gotpointercapture   pointerId=-1239851261   (= the Touch.identifier)
    lostpointercapture  pointerId=-1239851261   willCancel=true
    cancelDrag
  touchmove #2..#50     drag gone; the sheet ignores the rest of the pull

Chromium keeps the two id spaces apart, so emulated touch never reproduces it;
the unit tests stub `setPointerCapture`, so jsdom never fires the cancelling
event. The handle keeps working because it runs on real pointer events, which
legitimately hold the capture. The mid-gesture content-end handoff (#5172)
usually survives only by timing: it promotes after WebKit has already given up
that pointer at scroll commit.

Touch-driven drags are now marked as such. They take no pointer capture, and
`lostpointercapture`, `pointercancel` and `pointermove` for the same finger no
longer cancel, end, or double-drive them.

Test Plan:
- Two new cases in useSheetGestures.test.ts dispatch onLostPointerCapture and
  onPointerCancel with a pointerId equal to the touch identifier. Both fail on
  main ("expected false to be true") and pass here.
- packages/core/src/BottomSheet suite: 163/163.
- On an iPhone 17 Simulator (iOS 26.5), one continuous touch per case, sheet
  at the 0.5 detent; numbers are the scrolling body's height, 309 = mid detent,
  395 = fully open:

  | case                                     | before      | after     |
  |------------------------------------------|-------------|-----------|
  | fresh touch at the content end, pull up  | 309 (inert) | 309 -> 395|
  | scroll to the end mid-gesture, keep pull | 309 -> 395  | unchanged |
  | top-edge pull-down in the body           | 395 -> 309  | unchanged |
  | ordinary mid-content scroll              | scroll only | unchanged |
  | grab-handle drag                         | works       | works     |

- tsc --noEmit clean; lint:strict 0 errors.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 18, 2026
@vercel

vercel Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 18, 2026 6:07am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

BottomSheet (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 3018 -
Complexity N/A Very High (244) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 18, 2026
@imdreamrunner
imdreamrunner merged commit 2022d94 into main Aug 18, 2026
18 checks passed
@github-actions
github-actions Bot deleted the fix/bottom-sheet-ios-pointer-id-collision branch August 19, 2026 06:11

This branch was successfully deployed

1 active deployment
Preview — 7c8e437f Deployed Aug 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant