Repository navigation
[drawer] Drive swipe gestures natively to stop per-frame re-rasterization - #4980
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,106.74 ms ▼-522.70 ms(-32.1%) | Renders: 50 (+0) | Paint: 1,689.40 ms ▼-739.28 ms(-30.4%)
…and 6 more (+1 within noise) — details 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. |
979a995 to
0740b7c
Compare
0740b7c to
53c5e5a
Compare
Review (Claude Fable 5): base-ui#4980 — [drawer] Drive swipe gestures nativelyThis routes drawer swipe moves through the existing document-level capture-phase Correctness — traced the forwarding path end to end:
Notes:
Tests cover both the claimed path (consumer handler not called) and the preserved native-scroll path (handler called once), and the LGTM — the notes above are observations, not blockers. |
Fixes #4863
Problem
While a Drawer was open, every swipe
touchmovere-rasterized the sheet's content instead of staying compositor-only. Thetouchmovebubbled into React's delegated touch system, and processing it there made Chrome invalidate and repaint the document and full-screen popup once per move (~2 paints per move). The translate was already a cheap composited transform — the repaints came from the event-dispatch path.Fix
Drive the swipe from a native, capture-phase
touchmovelistener. Once the Drawer claims the gesture it callsstopPropagation()so the move never reaches React's delegated handlers, forwarding it via a typedmoveFromNativeTouchhook method. Propagation is preserved for cases the Drawer must not hijack (native scroll, range inputs, pinch-zoom, text selection).getDragTransformalso moves totranslate3d. No consumer CSS or workarounds required.Results
Heavy drawer stress benchmark (800-node payload, includes Vaul), headless Chromium, 20× CPU slowdown, paired same-session runs, medians:
Base UI before → after: paint 341 → 70 ms (−79%), paint events 78 → 6, avg move task 17.1 → 8.9 ms (−48%), total busy −36%. The per-move content re-rasterization is gone; paint no longer scales with the heavy content.
Notes: numbers reflect main-thread work during the gesture.
Total busy= all main-thread time in the swipe window;Avg move task= per-move input-handler latency — not comparable across libraries (Silk travels via native scroll, so it offloads the drag to the compositor and delivers fewer JS moves). Material UI'sSwipeableDrawerkeeps an 800-node paper mounted while closed, which inflates absolute numbers for every row equally, so treat cross-library absolutes loosely; the Base UI before/after delta is unaffected.Before
After
Changes
touchmovelistener and callstopPropagation()so they don't reach React's delegated handler. Native scroll, range inputs, pinch-zoom, and text selection still propagate.moveFromNativeTouchtouseSwipeDismissso the native listener feeds the gesture without a synthetic React event.translate3d.