Skip to content

fix(core): a BottomSheet drag writes its transform per move, not per render - #7169

Merged
imdreamrunner merged 1 commit into
meta:mainfrom
vjeux:sheet-drag-off-render
Oct 8, 2026
Merged

imdreamrunner merged 1 commit into
meta:mainfrom
vjeux:sheet-drag-off-render

Conversation

@vjeux

@vjeux vjeux commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

User impact

Anyone dragging a BottomSheet by 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: useSheetGestures keeps the live drag offset in React state (setDragOffset per move); BottomSheetPanel renders 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 writeLiveTransform helper, an isTraveling flag replacing the per-move derivation the host used, activeOffsetRef exposed 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; dragOffset stays on the result as the value the host last rendered against.

Evidence

  • Reproduction before the change: Chromium, 390x844 touch emulation, the SnapPoints story, a 24-sample handle drag through CDP: 49 React commits during the drag (BottomSheetDrag.a11y.chromium.spec.ts red on main: Expected: <= 4, Received: 49).
  • Result after the change: 4 commits for the same drag (begin, traveling, and the two around them); the inline transform follows the finger per sample (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 reads translateY(93.8px) on its way back from 115, and it reaches rest.
  • Representative unchanged path: all 232 BottomSheet unit tests pass, including 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.
  • Regression test or other mutation-sensitive proof: useSheetGestures.test.ts > renders nothing for a move that keeps the layout split (fails on main: 3 renders for 3 moves) and restores the full layout height when a drag crosses above its base; the Chromium spec above.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm vitest run packages/core/src/BottomSheet
 Test Files  7 passed (7)
      Tests  232 passed (232)
pnpm storybook:build && ASTRYX_STORYBOOK_DIR=apps/storybook/dist pnpm exec playwright test packages/core/src/BottomSheet/__tests__/BottomSheetDrag.a11y.chromium.spec.ts --project=chromium
  1 passed (3.0s)   # 3/3 on --repeat-each=3; against a main build: Expected: <= 4, Received: 49
pnpm exec eslint packages/core/src/BottomSheet   # clean
pnpm --filter @astryxdesign/core exec tsc --noEmit   # clean

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.transform both engines already read.

…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.
@vercel

vercel Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 8, 2026 12:21pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 8, 2026
@astracat-bot

astracat-bot Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 8, 2026, 12:39 PM UTC

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

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

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

23 of 442 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 155,733
Chat Full AI Chat probe dark 155,005
Chat Default neutral dark 33,205
Chat Default neutral light 32,876
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,229
Chat With Attachments probe dark 11,065
TableRowExpansion Detail Panel neutral dark 5,129
TableRowExpansion Detail Panel neutral light 4,050
SideNav Resizable in AppShell probe light 3,208
TableGroupedRows Default neutral light 2,133
TableGroupedRows Default neutral dark 2,116
Markdown Default probe dark 897
Markdown Default probe light 897
Markdown Default neutral dark 882

and 3 more.


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

@imdreamrunner
imdreamrunner merged commit a83e568 into meta:main Oct 8, 2026
39 checks passed
@vjeux
vjeux deleted the sheet-drag-off-render branch October 8, 2026 20:05
cixzhang added a commit that referenced this pull request Oct 8, 2026
#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.

This branch was successfully deployed

1 active deployment
Preview — 5681aec1 Deployed Oct 8, 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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants