[scroll area] Reduce bundle size#5217
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,546.21 ms +135.41 ms(+9.6%) | Renders: 78 (+0) | Paint: 2,394.68 ms +214.50 ms(+9.8%)
10 tests within noise — details Metric alarms
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. |
There was a problem hiding this comment.
Pull request overview
This PR reduces the bundle size of @base-ui/react/scroll-area without changing the public API by consolidating duplicated axis-specific logic, avoiding redundant state objects, and inlining internal-only enum strings (with tests to keep the strings in sync).
Changes:
- Consolidated vertical/horizontal pointer and track-click logic into axis-parameterized code paths.
- Moved viewport “state” to the root context (
viewportState) to avoid rebuilding objects on scroll frames. - Inlined CSS variable and data-attribute strings for better tree-shaking, adding tests to ensure the inlined strings stay synced with the exported enums used for docs.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/scroll-area/viewport/ScrollAreaViewport.tsx | Inlines overflow CSS vars, reuses root-provided viewportState, and reduces scroll-frame allocations via pickState. |
| packages/react/src/scroll-area/utils/getOffset.ts | Simplifies logical margin/padding reads and avoids repeated parsing. |
| packages/react/src/scroll-area/thumb/ScrollAreaThumb.tsx | Updates scrollbar context consumption and inlines thumb CSS var usage. |
| packages/react/src/scroll-area/thumb/ScrollAreaThumb.test.tsx | Adds browser-only horizontal dragging coverage (LTR/RTL) and pointer capture assertions. |
| packages/react/src/scroll-area/scrollbar/ScrollAreaScrollbarContext.ts | Simplifies context value to a string union for better bundle output. |
| packages/react/src/scroll-area/scrollbar/ScrollAreaScrollbar.tsx | Consolidates track-click logic by axis, uses viewportState, and inlines CSS var strings. |
| packages/react/src/scroll-area/scrollbar/ScrollAreaScrollbar.test.tsx | Adds browser-only track-click coverage across axis + LTR/RTL. |
| packages/react/src/scroll-area/root/stateAttributes.ts | Inlines data-attribute strings so the enum can tree-shake out. |
| packages/react/src/scroll-area/root/ScrollAreaRootContext.ts | Removes rootRef from context shape (root still owns it internally). |
| packages/react/src/scroll-area/root/ScrollAreaRoot.tsx | Consolidates scrolling timeout logic, inlines orientation attribute string, and inlines corner CSS var strings. |
| packages/react/src/scroll-area/root/ScrollAreaRoot.test.tsx | Improves ResizeObserver mocking and adds regression coverage for clearing overflow/corner state. |
| packages/react/src/scroll-area/enumSync.test.tsx | Pins inlined runtime strings to the exported enums to prevent drift. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3ff2486 to
fff0f95
Compare
Reduces the
@base-ui/react/scroll-areabundle size with no public API change. The bundle bot is authoritative for the current size impact.The vertical and horizontal branches in the scrollbar and root pointer handlers are consolidated into axis-parameterized paths, and the viewport reuses state already shared by the root. Internal enum members used only at runtime are inlined while their source enums remain for types and docs; an enum-sync test prevents the strings from drifting.
Emitted DOM attributes, CSS variables, and state remain unchanged.