Skip to content

[drawer] Don't let a trailing stationary pointermove cancel release velocity - #5658

Merged
atomiks merged 5 commits into
mui:masterfrom
padd60:fix/swipe-release-velocity-time-window
Sep 23, 2026
Merged

atomiks merged 5 commits into
mui:masterfrom
padd60:fix/swipe-release-velocity-time-window

Conversation

@padd60

@padd60 padd60 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

recordDragSample in useSwipeDismiss derives the release velocity from the last two pointer samples. Chrome on Android emits a final, effectively stationary pointermove immediately before pointerup, and that one sample overwrites the stored velocity.

Measured on a Galaxy Z Flip 4 (Android 16, Chrome 151, DPR 2.8125) — the tail of a normal upward flick on a Drawer with snap points, as dy / dt per pointermove:

… −35.5/8.3ms   −66.2/8.2ms   −0.7/7.8ms    ← last pointermove
pointerup                       0/8.2ms      ← same coordinates

releaseVelocityY comes out as −0.7 / max(7.8, 16) = −0.04 px/ms while the finger was moving at 2–4 px/ms. This was consistent across 45 recorded gestures: the trailing sample advanced 0.1–0.7px every time, and pointerup always carried the same coordinates as the last move (Δ = 0), so the existing sampleVelocity !== 0 guard correctly keeps lastDragVelocityRef — but that value is already polluted.

The user-visible effect with Drawer + snapPoints + snapToSequentialPoints: shouldAdvance in DrawerViewport requires |velocity| >= 0.5 px/ms, so it never fires on Android and the snap decision degrades to "nearest snap point by raw drag distance". A flick then has to travel more than half the gap between two snap points to move a single step. iOS and desktop are unaffected because they don't emit the trailing sample.

Changes

  1. Fall back to a 50ms window when the newest sample did not advance by at least a pixel. A sample that did advance keeps the previous two-sample reading, so a deceleration before the release still reports its own low velocity — keeps the drawer open on low-velocity swipes near a snap point relies on that and stays green, as do the three existing velocity tests.
  2. Keep stationary samples out of that window. Otherwise input arriving slower than the window leaves the stationary sample as the window start and the velocity collapses again (0.03 px/ms for a 180px drag in my test). A genuine hold still dilutes the velocity, because the window start keeps ageing while the offset stops changing.
  3. Clear lastDragVelocityRef when a gesture starts. The window now begins empty, so the first sample of a gesture no longer recomputes the velocity as a side effect. A gesture that ends without a move event would otherwise report the previous gesture's velocity.

The distinction in (1) is the only one the event stream actually offers: a real deceleration and Chrome's phantom sample have comparable durations (19ms vs 8ms in my data), but the phantom advances sub-pixel while a deceleration advances at least a pixel. If you would rather draw that line differently, I am happy to rework it.

Verification

Controlled experiment via CDP Input.dispatchTouchEvent on the device. Identical 150px flick, differing only by the trailing stationary sample:

gesture before after
150px flick + trailing stationary sample snaps back advances one step
150px flick without it advances one step advances one step
20px drag + trailing stationary sample snaps back snaps back

With a real finger, flicks of 16–61px now advance a snap step, and a 20px drag still does not.

Three regression tests added, one per change. Against master they report 0.03125, 0.03125 and -0.02 where they expect 1.5125, 1.4102 and 0.

Full suites green: VITEST_ENV=jsdom 7799 passed, VITEST_ENV=chromium 8896 passed (@base-ui/react + @base-ui/utils).

🤖 Generated with Claude Code

@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5658
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5658
    

commit: 75ad80c

@code-infra-dashboard

code-infra-dashboard Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+228B(+0.05%) 🔺+58B(+0.04%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 75ad80c
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ab397bd008ac70008d5e961
😎 Deploy Preview https://deploy-preview-5658--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@padd60
padd60 force-pushed the fix/swipe-release-velocity-time-window branch from 86f839e to b4180d0 Compare September 10, 2026 03:45
…elocity

Chrome on Android emits a final, effectively stationary `pointermove` right
before `pointerup`. `recordDragSample` derived the release velocity from the
last two samples, so that one sample overwrote the real velocity and reported
a stopped finger.

- Fall back to a 50ms window of samples when the newest sample did not advance
  by at least a pixel. A sample that did advance keeps the previous two-sample
  reading, so a deceleration before the release still reports its own low
  velocity and the existing velocity tests are unchanged.
- Keep stationary samples out of that window. Otherwise input arriving slower
  than the window leaves the stationary sample as the window start and the
  velocity collapses again. A genuine hold still dilutes the velocity, because
  the window start keeps ageing while the offset stops changing.
- Clear `lastDragVelocityRef` when a gesture starts. The window now begins
  empty, so a gesture that ends without a move event would otherwise report
  the previous gesture's velocity instead of zero.
@padd60
padd60 force-pushed the fix/swipe-release-velocity-time-window branch from b4180d0 to f90d93a Compare September 10, 2026 04:08
@atomiks atomiks added the component: drawer Changes related to the drawer component. label Sep 10, 2026
@atomiks
atomiks force-pushed the fix/swipe-release-velocity-time-window branch from 666716d to f299cac Compare September 10, 2026 10:55
@atomiks atomiks added the type: bug It doesn't behave as expected. label Sep 23, 2026
@atomiks
atomiks merged commit eb23efa into mui:master Sep 23, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: drawer Changes related to the drawer component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants