[slider] Reduce bundle size#5222
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,214.19 ms -83.31 ms(-6.4%) | Renders: 78 (+0) | Paint: 1,889.27 ms -109.54 ms(-5.5%)
11 tests 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. |
f75addb to
2897012
Compare
There was a problem hiding this comment.
Pull request overview
Behavior-preserving bundle-size reduction pass over @base-ui/react/slider by simplifying small helpers, removing a couple of thin utility wrappers, and switching a few internal hot-path helpers to positional arguments to improve minification. The PR also adds targeted regression tests around swap behavior, indicator parity, and interaction-state cleanup.
Changes:
- Simplify/inline slider internal utilities (map/loops, remove tiny helpers, reuse shared mappings).
- Convert internal helper APIs (
resolveThumbCollision,getPushedThumbValues,getMidpoint) to smaller positional signatures and update call sites/tests. - Add regression tests for swap focus/active index, indicator parity across orientations/directions, enum-to-runtime alignment, and controlled-range growth mid-drag.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/slider/value/SliderValue.tsx | Simplifies formatting and htmlFor construction for smaller output rendering. |
| packages/react/src/slider/utils/valueArrayToPercentages.ts | Removes unused/duplicative utility to reduce bundle surface (file deleted). |
| packages/react/src/slider/utils/validateMinimumDistance.ts | Replaces array allocation + Math.min(...distances) with early-exit loop. |
| packages/react/src/slider/utils/resolveThumbCollision.ts | Switches to positional args, hoists shared work, and fast-paths push. |
| packages/react/src/slider/utils/resolveThumbCollision.test.ts | Updates tests to match new resolveThumbCollision signature. |
| packages/react/src/slider/utils/replaceArrayItemAtIndex.ts | Removes thin wrapper in favor of local inlining (file deleted). |
| packages/react/src/slider/utils/getSliderValue.ts | Inlines array update/sort logic and simplifies non-range return path. |
| packages/react/src/slider/utils/getPushedThumbValues.ts | Switches to positional args to improve minification. |
| packages/react/src/slider/utils/getPushedThumbValues.test.ts | Updates tests to match new getPushedThumbValues signature. |
| packages/react/src/slider/utils/getMidpoint.ts | Removes Coords object allocation; returns a single axis midpoint. |
| packages/react/src/slider/thumb/SliderThumb.tsx | Reduces branching and allocations; inlines data-index; updates midpoint usage. |
| packages/react/src/slider/root/stateAttributesMapping.ts | Reuses a shared nullMapping function to shrink mapping literals. |
| packages/react/src/slider/root/SliderRootContext.ts | Removes unused pressedInputRef from context surface. |
| packages/react/src/slider/root/SliderRoot.tsx | Simplifies equality check and trims memo dependencies while preserving stability. |
| packages/react/src/slider/root/SliderRoot.test.tsx | Adds browser-mode regressions for swap focus/active index and cancel behavior. |
| packages/react/src/slider/indicator/SliderIndicator.tsx | Consolidates style computation into a single helper while preserving behavior. |
| packages/react/src/slider/indicator/SliderIndicator.test.tsx | Adds browser-mode parity coverage for keyboard behavior + indicator styling. |
| packages/react/src/slider/enumSync.test.tsx | Ensures runtime data-index matches the docs enum value. |
| packages/react/src/slider/control/SliderControl.tsx | Updates collision/midpoint calls, reduces cached refs, and tightens swap focusing. |
| packages/react/src/slider/control/SliderControl.test.tsx | Adds browser-mode regression to ensure cached interaction state is cleared on range growth mid-drag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3281639 to
cc75648
Compare
Reduces the
@base-ui/react/sliderbundle size without changing behavior or the public API. The bundle bot is authoritative for the current size impact.The cleanup consolidates control, indicator, thumb, root, and collision-resolution logic. Focused state-machine and enum-sync regressions cover the affected behavior and inlined state-attribute strings.