[utils] Move clamp, areArraysEqual, shadowDom, and formatNumber to utils#5167
Open
romgrk wants to merge 2 commits into
Open
[utils] Move clamp, areArraysEqual, shadowDom, and formatNumber to utils#5167romgrk wants to merge 2 commits into
romgrk wants to merge 2 commits into
Conversation
Relocate a first batch of domain-agnostic primitives from the react
package into the shared @base-ui/utils stdlib (usable across MUI + Base UI):
- clamp
- areArraysEqual (reimplemented with a referential short-circuit and a
reverse loop, inspired by fastArrayCompare from @mui/x-internals)
- shadowDom (activeElement, contains, getTarget)
- formatNumber + stringifyLocale
Update all import sites to @base-ui/utils/* and drop the now-obsolete
./internals/{areArraysEqual,clamp,shadowDom} export subpaths.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
commit: |
x-internals
Bundle size
PerformanceTotal duration: 1,247.83 ms +90.32 ms(+7.8%) | Renders: 78 (+0)
13 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. |
55e8cbb to
120d582
Compare
x-internals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First phase of moving domain-agnostic primitives out of
@base-ui/react'sinternals/andutils/into the shared@base-ui/utilsstdlib (usable across MUI + Base UI). These are pure, dependency-clean utilities with no Base UI-specific semantics.Moved (history preserved via
git mv):clamp— pure mathareArraysEqual— reimplemented inspired byfastArrayComparefrom@mui/x-internals: referential-equality short-circuit, early length bail-out, and a reverse loop that inlines the element check when no custom comparer is passed. UsesObject.isfor the default comparison (consistent with the siblingitemEqualityutil) soNaNvalues are treated as equal. The optionalitemComparerparameter is retained for the Select/Combobox call sites.shadowDom—activeElement,contains,getTarget(shadow-DOM-safe traversal)formatNumber+ itsstringifyLocaledependencyChanges
@base-ui/utils/*(17clamp, 4areArraysEqual, 8formatNumber, 1shadowDom, 1stringifyLocale)../internals/{areArraysEqual,clamp,shadowDom}export subpaths frompackages/react/package.json. The moved files are auto-exported via the utils package's./*glob.areArraysEqual(previously untested);clamp,formatNumber, andstringifyLocaletests moved alongside their sources and now run under the@base-ui/utilsproject.Follow-up
A subsequent phase will import the broader set of generic utilities currently living in
@mui/x-internals(e.g.hash,isDeepEqual,throttle,disposable, …) into@base-ui/utils, in coordination with a parallelmui-xPR that re-exports them from the stdlib. That work is intentionally kept out of this PR to keep the move small and reviewable.Verification
pnpm typescript✓pnpm eslint✓pnpm prettier✓pnpm test:jsdom clamp areArraysEqual formatNumber stringifyLocale✓ (13 tests)🤖 Generated with Claude Code