Skip to content

Conversation

@michaldudak
Copy link
Member

@michaldudak michaldudak commented Jun 25, 2025

Extracted utilities that can be used in other MUI projects to a separate library - @base-ui-components/utils.

Before we start using it across the company, I want to update JSDocs and possibly rename and reorganize few utilities.

@michaldudak michaldudak added the scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). label Jun 25, 2025
@michaldudak michaldudak requested a review from a team June 25, 2025 15:56
@mui-bot
Copy link

mui-bot commented Jun 25, 2025

Bundle size report

Bundle Parsed Size Gzip Size
@base-ui-components/react ▼-295B(-0.10%) ▼-124B(-0.13%)

Details of bundle changes

Generated by 🚫 dangerJS against c4c063a

@Janpot
Copy link
Member

Janpot commented Jun 25, 2025

can be used in other MUI projects to a separate library

That means they will be semver stable? Should we document them?

cc @romgrk to get your attention on this PR, I believe you brought up the topic of shared libraries recently.

@@ -0,0 +1,3 @@
# @base-ui-components/react-utils
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd go with just @base-ui-components/utils for the name. The package contains more than just react-specific utils, and the name is already long due to the prefix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm fine with it too. I'm wondering if it shouldn't be internal-utils, though, to match the convention we use in other such libraries (@Janpot, any opinions?).

Copy link
Member

Choose a reason for hiding this comment

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

According to the current conventions, that would make it semver unstable and then it can only be depended in this repo, and only if the dependency is defined with exact version.
I think @base-ui-components/utils makes sense, just don't make breaking changes in it on a minor.

Copy link
Contributor

Choose a reason for hiding this comment

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

That means they will be semver stable? Should we document them?

Yes it should follow semver, and no I don't think we should document them beyond jsdoc.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 26, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 26, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 26, 2025

vite-css-base-ui-example

npm i https://pkg.pr.new/@base-ui-components/react@2167
npm i https://pkg.pr.new/@base-ui-components/utils@2167

commit: c4c063a

@netlify
Copy link

netlify bot commented Jun 26, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit c4c063a
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6870c96a87c30f00088628cc
😎 Deploy Preview https://deploy-preview-2167--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.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 30, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 2, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 2, 2025
@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Jul 7, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 8, 2025
useSpringRef,
} from '@react-spring/web';
// eslint-disable-next-line no-restricted-imports
import { useTransitionStatus } from '@base-ui-components/react/utils/useTransitionStatus';
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be -

Suggested change
import { useTransitionStatus } from '@base-ui-components/react/utils/useTransitionStatus';
import { useTransitionStatus } from '@base-ui-components/utils/useTransitionStatus';

Copy link
Member Author

Choose a reason for hiding this comment

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

No, useTransitionStatus is Base UI-specific and lives in the main package.

import * as ReactDOM from 'react-dom';
import { useScrollLock } from '@base-ui-components/react/utils';
// eslint-disable-next-line no-restricted-imports
import { useScrollLock } from '@base-ui-components/react/utils/useScrollLock';
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 8, 2025
Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

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

Great work!
Thank you for exporting these. 🙏
Leaving some minor nitpicks.

I've tested it on mui/mui-x#18734 and have a question.
Have you considered exporting useButton hook? 🤔

useSpring,
useSpringRef,
} from '@react-spring/web';
// eslint-disable-next-line no-restricted-imports
Copy link
Member

Choose a reason for hiding this comment

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

If this package does not have problems importing files from more than 2 levels deep, then maybe the ESLint rules should be adjusted? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't really import these from the package. Docs use Base UI sources directly, so they can access private exports.

Copy link
Member

Choose a reason for hiding this comment

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

Docs use Base UI sources directly

Is this avoidable? this tends to mess up caching algorithms that rely only on npm dependencies. and all kinds of other subtle problems, e.g. typescript filles outside of the root folder and stuff like that

Copy link
Contributor

Choose a reason for hiding this comment

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

It does create subtle problems, but it also makes the devmode DX much nicer. HMR works seamlessly if you use source files rather than built files, and you can import anything you want. The setup is harder to maintain, but the tradeoff is worth it, imho.

Copy link
Member

@dav-is dav-is Jul 9, 2025

Choose a reason for hiding this comment

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

HMR works seamlessly if you use source files rather than built files

I think for this case, we should be using a watch script for typescript builds of the lib. HMR should work fine on the built files after they are updated by the typescript watcher.

I think another good purpose of the docs is testing that our packaging is working properly. I could see an issue if there were subtle differences in the typescript config between the docs and the lib.

Also, why do the docs need to access private exports?

Copy link
Member

@Janpot Janpot Jul 9, 2025

Choose a reason for hiding this comment

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

if necessary we can alias to sources for dev mode, I don't mind so much, as long as the aliasing can be removed and no code changes are necessary for regular pnpm workspaces resolution to work correctly.

each package building in watch mode has my preference, but we need to make sure it can scale to the size of core and X monorepos. We'll likely start work on a vite configuration for building our libraries soon.

Copy link
Contributor

@romgrk romgrk Jul 9, 2025

Choose a reason for hiding this comment

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

I could see an issue if there were subtle differences in the typescript config between the docs and the lib.

I have witnessed such issues in the past, but I argued unsuccessfully for running our test suites (rather than the docs) in prod mode to deal with that.

Also, why do the docs need to access private exports?

Private experiments that we don't want to publish, such as this case and anything else under .../(private)/experiments/.

I think for this case, we should be using a watch script for typescript builds of the lib. HMR should work fine on the built files after they are updated by the typescript watcher.

If it can be shown to not affect the DX, I'm fine with it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this avoidable? this tends to mess up caching algorithms that rely only on npm dependencies. and all kinds of other subtle problems, e.g. typescript filles outside of the root folder and stuff like that

We can discuss it on the infra meeting. It's not in scope of this PR anyway.

Co-authored-by: Lukas Tyla <llukas.tyla@gmail.com>
Signed-off-by: Michał Dudak <michal.dudak@gmail.com>
@michaldudak
Copy link
Member Author

Have you considered exporting useButton hook? 🤔

We might actually have a Button component at some point, but it's not fully decided yet.
If you need to add button functions to a non-interactive component, I suppose useButton could be useful. However, before we export it, I'd like to clean it up properly and remove handling of HTML anchors (we could have useLink if there's a need, but I don't see it now).

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 11, 2025
@michaldudak michaldudak merged commit cbfd881 into mui:master Jul 11, 2025
21 checks passed
@michaldudak michaldudak deleted the utils-library branch July 11, 2025 08:27
@michaldudak michaldudak added the package: utils Specific to the utils package. label Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: utils Specific to the utils package. scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants