Repository navigation
[drawer] Don't let a trailing stationary pointermove cancel release velocity - #5658
Merged
atomiks merged 5 commits intoSep 23, 2026
Merged
Conversation
padd60
requested review from
atomiks,
colmtuite,
flaviendelangle,
jjenzz and
michaldudak
as code owners
September 10, 2026 03:34
commit: |
Bundle size
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
padd60
force-pushed
the
fix/swipe-release-velocity-time-window
branch
from
September 10, 2026 03:45
86f839e to
b4180d0
Compare
…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
force-pushed
the
fix/swipe-release-velocity-time-window
branch
from
September 10, 2026 04:08
b4180d0 to
f90d93a
Compare
atomiks
force-pushed
the
fix/swipe-release-velocity-time-window
branch
from
September 10, 2026 10:55
666716d to
f299cac
Compare
atomiks
approved these changes
Sep 23, 2026
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
recordDragSampleinuseSwipeDismissderives the release velocity from the last two pointer samples. Chrome on Android emits a final, effectively stationarypointermoveimmediately beforepointerup, 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
Drawerwith snap points, asdy / dtperpointermove:releaseVelocityYcomes out as−0.7 / max(7.8, 16) = −0.04 px/mswhile 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, andpointerupalways carried the same coordinates as the last move (Δ = 0), so the existingsampleVelocity !== 0guard correctly keepslastDragVelocityRef— but that value is already polluted.The user-visible effect with
Drawer+snapPoints+snapToSequentialPoints:shouldAdvanceinDrawerViewportrequires|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
keeps the drawer open on low-velocity swipes near a snap pointrelies on that and stays green, as do the three existing velocity tests.0.03 px/msfor a 180px drag in my test). A genuine hold still dilutes the velocity, because the window start keeps ageing while the offset stops changing.lastDragVelocityRefwhen 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.dispatchTouchEventon the device. Identical 150px flick, differing only by the trailing stationary sample: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
masterthey report0.03125,0.03125and-0.02where they expect1.5125,1.4102and0.Full suites green:
VITEST_ENV=jsdom7799 passed,VITEST_ENV=chromium8896 passed (@base-ui/react+@base-ui/utils).🤖 Generated with Claude Code