Repository navigation
fix(core): a BottomSheet drag writes its transform per move, not per render - #7169
Conversation
…render useSheetGestures held the live drag offset in React state, so every pointer or touch sample re-rendered the panel before the transform reached the element: one commit per input sample (49 commits for a 24-sample drag in Chromium), the sheet following the finger at the main thread's cadence rather than the input's, and visibly behind it on a busy page. The move handler now writes the compositor transform straight to the sheet element and renders nothing; the live offset is readable through activeOffsetRef. State changes when a drag begins, when the sheet first travels (one change, for the host's keyboard dismissal), when the layout split crosses the base detent (the host renders the new height), and when the drag ends. The panel owns the element's transform outside a drag and writes the resting value after each commit instead of rendering it through the style prop, so React, which never saw the live writes, cannot skip a value it believes unchanged: the settle and the dismissal animate from wherever the finger left the sheet, in the same style update that restores the transition.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
This is a nicely scoped restorative fix: a BottomSheet drag now writes its transform directly to the sheet once per input sample instead of re-rendering between sample and paint, and the panel restores the resting transform after the drag so the settle still animates from the live position.
What I verified:
- For the same 24-sample touch drag in the SnapPoints story, the sheet followed to the same final drag position and returned to rest before and after, with no visual change in the captured frames.
- The reviewed browser measurement was 4 React commits after the change versus 30 for the same drag in the dev Storybook before it, consistent with the result reported in the PR.
- The BottomSheet suite passes (232 tests), including the panel, switcher, gesture, and keyboard paths, and no violations were reported by axe on the open-sheet state.
- No public API, default, snap, dismissal, or visual behavior changes.
Two small non-blocking notes: a caller that supplies its own style.transform can have it overwritten by the live drag and not restored by the new effect guard, and the new layout-crossing unit test repeats the same liveOffset assertion where an assertion on the rendered dragOffset would be more mutation-sensitive.
Overall, this looks ready.
[Automated review]
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression23 of 442 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 3 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
#7188) #7168 added "promotes a pull-down from the top of a nested scroller", which asserted the sheet's position through `dragOffset`. #7169 merged 90 seconds later from a base without that test: it moved the live drag position out of React state (to `activeOffsetRef` and the element's transform) and redefined `dragOffset` as the offset last rendered for a layout-split change, migrating every existing assertion but not this new one. The product still promotes the pull-down and moves the sheet 60px; only the stale read fails, on main and on every PR. Assert the live offset and the transform written to the sheet element, as the other drag assertions do since #7169.
User impact
Anyone dragging a
BottomSheetby its handle or by pulling its content on a phone. The sheet followed the finger at the main thread's cadence, not the input's: every pointer or touch sample re-rendered the panel before the transform reached the element, so on a page with anything else going on (images decoding, a list updating) the drag stuttered and trailed the finger. With the change a drag costs one style write per sample and no render, and the release still animates from wherever the finger left the sheet.Problem and solution fit
Why it occurs:
useSheetGestureskeeps the live drag offset in React state (setDragOffsetper move);BottomSheetPanelrenders the transform from it through the style prop. One input sample, one commit.Why it harms the task: the drag is the gesture the sheet exists for, and it is the one path on which React sits between the input and the paint. The transform itself is already compositor-friendly (
will-change: transform); the write to it was not.Why it matters: a sheet that lags the finger reads as broken on exactly the devices sheets are for.
The fix writes the compositor transform to the sheet element in the move handler and renders nothing between samples. State changes when a drag begins, when the sheet first travels (one change, for the host's keyboard dismissal), when the layout split crosses the base detent (the host must render the new height), and when the drag ends. Because React never sees the live writes, the panel now owns the element's transform outside a drag and writes the resting value after each commit instead of rendering it through the style prop; otherwise a settle back to the same detent would be skipped as "unchanged" and the sheet would stay where the finger left it. Written after the commit, the resting value lands in the same style update as the restored transition, so settles and dismissals animate from the live position.
Expected behavior and authority
The hook's own contract (file header): gestures and snaps only move the transform, "so they stay on the compositor", and "pointermove doesn't churn renders" (the drag bookkeeping is already in refs for that reason). This restores that intent for the one value that still rendered per move.
Smallest restoration
The move handler's write, a
writeLiveTransformhelper, anisTravelingflag replacing the per-move derivation the host used,activeOffsetRefexposed for the live number, and the panel's transform moving from the style prop to a layout effect. No public API, visual, default, or interaction change;dragOffsetstays on the result as the value the host last rendered against.Evidence
BottomSheetDrag.a11y.chromium.spec.tsred onmain:Expected: <= 4, Received: 49).5, 9.8, 16.9, 26.8, 40, 45, ... 115, the first samples easing out of the detent magnet as before); 40 ms after release the computed transform readstranslateY(93.8px)on its way back from 115, and it reaches rest.BottomSheet.test.tsx's inline-transform assertions during drags and at rest and the switcher's retained alignment offset (toHaveStyle({transform: 'translateY(120px)'})), which now reaches the element through the effect.useSheetGestures.test.ts>renders nothing for a move that keeps the layout split(fails onmain: 3 renders for 3 moves) andrestores the full layout height when a drag crosses above its base; the Chromium spec above.Scope
Testing
Real browser: Chromium phone emulation as above (handle drag, release, snap back). Not run on WebKit here (the box cannot launch it); the write path is the same inline
style.transformboth engines already read.