Skip to content

[utils] Move getFilter, serializeValue, and stringifyAsLabel to @base-ui/utils#4449

Draft
flaviendelangle wants to merge 3 commits intomui:masterfrom
flaviendelangle:move-filter-to-utils
Draft

[utils] Move getFilter, serializeValue, and stringifyAsLabel to @base-ui/utils#4449
flaviendelangle wants to merge 3 commits intomui:masterfrom
flaviendelangle:move-filter-to-utils

Conversation

@flaviendelangle
Copy link
Copy Markdown
Member

I need to access those utils on the Tree component in the new repo.

Summary

  • Moves serializeValue, stringifyAsLabel, and the Filter/getFilter utilities from @base-ui/react internal utils to @base-ui/utils so they can be shared across packages.
  • Updates all imports in @base-ui/react to use @base-ui/utils/filter, @base-ui/utils/serializeValue, and @base-ui/utils/stringifyAsLabel directly.
  • Deletes the now-unused packages/react/src/utils/serializeValue.ts file.

Test plan

  • TypeScript type-checking passes
  • ESLint passes on all changed files
  • Combobox tests pass (649 tests)

🤖 Generated with Claude Code

flaviendelangle and others added 2 commits March 26, 2026 08:48
…/utils

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@flaviendelangle flaviendelangle self-assigned this Mar 26, 2026
@flaviendelangle flaviendelangle added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. component: combobox Changes related to the combobox component. labels Mar 26, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 26, 2026

commit: 7cc43d8

@mui-bot
Copy link
Copy Markdown

mui-bot commented Mar 26, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 0B(0.00%) 🔺+7B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 26, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 68a406b
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69c4e6581a613d0009aca804
😎 Deploy Preview https://deploy-preview-4449--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@flaviendelangle
Copy link
Copy Markdown
Member Author

flaviendelangle commented Mar 26, 2026

Claude Code review

Summary

This PR extracts three utilities from @base-ui/react internal code into the shared @base-ui/utils package so they can be reused by the Tree component in another package.

Moved utilities:

  • getFilter + Filter / GetFilterParameters types → packages/utils/src/filter.ts
  • serializeValuepackages/utils/src/serializeValue.ts (renamed from packages/react/src/utils/serializeValue.ts)
  • stringifyAsLabelpackages/utils/src/stringifyAsLabel.ts (extracted from resolveValueLabel.tsx)

Review Verdict: Looks good ✓

The PR is a clean mechanical extraction with no logic changes. All imports are correctly updated and no stale references remain.

What's done well

  1. Exact code preservationstringifyAsLabel and the getFilter/Filter/cache logic are byte-for-byte identical to the originals. serializeValue is a pure rename (100% similarity).

  2. Backward compatibility in useFilter.ts — Re-exports UseFilterOptions as an alias for GetFilterParameters and keeps useCoreFilter as a typed wrapper around getFilter, so internal consumers don't break.

  3. No stale imports left — Verified: no file in packages/react/ still imports stringifyAsLabel from resolveValueLabel, serializeValue from the old local path, or Filter from the old useFilter location.

  4. Package exports workpackages/utils/package.json uses a "./*": "./src/*.ts" wildcard, so @base-ui/utils/filter, @base-ui/utils/serializeValue, and @base-ui/utils/stringifyAsLabel all resolve correctly without any config changes.

  5. Second commit cleans up — The follow-up commit removes an unnecessary stringifyAsLabel re-export from resolveValueLabel.tsx while keeping the import (which is still used by resolveSelectedLabel at line 77).

Minor observations (non-blocking)

  1. No dedicated unit tests for the extracted utilsstringifyAsLabel, serializeValue, and getFilter are now standalone public utilities in @base-ui/utils but don't have their own test files. They're exercised indirectly through the Combobox tests. Consider adding targeted unit tests if these will be consumed by multiple packages going forward.

  2. useCoreFilter naming — This is pre-existing, but useCoreFilter follows React hook naming convention (use prefix) while it's just getFilter (a plain function, not a hook). Not introduced by this PR, so not actionable here.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 26, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 7cc43d8
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69c4e6b59ee33f000892d289
😎 Deploy Preview https://deploy-preview-4449--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

What do you think of depending on @base-ui/react in other packages instead of placing some of these in @base-ui/utils? Reason is, the utils package is meant to be low-level stuff that could be used in any repository (core, X), whereas @base-ui/react is Base UI proper. The utils package is only in the @base-ui org because we needed to put it somewhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I know that we don't want to expose stuff from @base-ui/react as stable everytime we want to use it in other package within the company. The package is stable and we care a lot about its DX so anything made public there should be made public because we want people to use it, not because of internal needs.

With that being said, we have two alternatives to this:

  • expose stuff from @base-ui/react as unstable_
  • create a new @base-ui/internals package

I just don't want us to loose time figuring out how to share some code everytime we need a new util.
Because this will happen more and more as we create new packages.

We have a broader ongoing discussing on Slack and Notion

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: combobox Changes related to the combobox component. PR: out-of-date The pull request has merge conflicts and can't be merged. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants