Skip to content

Conversation

@romgrk
Copy link
Contributor

@romgrk romgrk commented Dec 1, 2025

Simplify controlled values and small changes to match the Store in X.

@romgrk romgrk 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. performance labels Dec 1, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 1, 2025

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/react@3384
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/utils@3384
    

commit: f3873f4

@mui-bot
Copy link

mui-bot commented Dec 1, 2025

Bundle size report

Bundle Parsed size Gzip size
@base-ui-components/react ▼-138B(-0.03%) ▼-9B(-0.01%)

Details of bundle changes


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

@netlify
Copy link

netlify bot commented Dec 1, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit f3873f4
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6931a15e0755d00008474a7a
😎 Deploy Preview https://deploy-preview-3384--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.

@romgrk romgrk changed the title [internal] Performance: refactor the store [internal] Refactor the store Dec 1, 2025
@romgrk romgrk removed the performance label Dec 1, 2025
@romgrk romgrk marked this pull request as ready for review December 1, 2025 16:07
* Do not modify properties in state directly. Instead, use the provided methods to ensure proper state management and listener notification.
*/
public state: State;
state: State;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want this file to be a copy-paste of the one in X, I've sync'ed the two and removed the public modifiers (which are the default) to match the convention with classes in the rest of the codebase.

Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't X import this one?

Copy link
Contributor Author

@romgrk romgrk Dec 2, 2025

Choose a reason for hiding this comment

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

By "this one", do you mean why isn't X importing this file directly?

It's because if we have Store tweaks to do, managing releases with BUI is too painful. I tried to do a utils-only release one time, but some people were opposed to it. So anyway, because we can't easily do tweaks on BUI utils, we have them duplicated in the X codebase at multiple places. Yay.

@romgrk romgrk marked this pull request as draft December 1, 2025 17:46
@romgrk romgrk marked this pull request as ready for review December 2, 2025 00:23
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Dec 2, 2025
@oliviertassinari oliviertassinari added the internal Behind-the-scenes enhancement. Formerly called “core”. label Dec 2, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Dec 2, 2025
*
* @param key Key of the selector to use.
*/
public useState = ((key: keyof Selectors, a1?: unknown, a2?: unknown, a3?: unknown) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've avoided the method = () => { ... } syntax when possible, because that's +1 memory allocation for each instance, and with stores being widespread it make sense to keep them lean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change complexifies a bit the open-by-default feature of menu/tooltips, but it keeps the Store simple, and I'd rather have the core of the codebase be simple.

We could make the controlled props more ergonomic, I also thought about joining the two fields in some standardized way, e.g. call them open and open:controlled-prop, then we could derive selectors & effects automatically, but I've kept this simple for now.

* Do not modify properties in state directly. Instead, use the provided methods to ensure proper state management and listener notification.
*/
public state: State;
state: State;
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't X import this one?

this.setState(newState);
}

use<F extends (...args: any) => any>(selector: F, ...args: SelectorArgs<F>): ReturnType<F>;
Copy link
Member

Choose a reason for hiding this comment

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

Wasn't Store supposed to be library-agnostic with React-specific methods in ReactStore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did say that but it's not a good split. We're only doing React, it doesn't make sense to consider anything else, and some of these methods are too ergonomic to skip them. What I wanted to avoid was mainly the overhead from BUI features like the controlled values, which was the main reason to not merge the store classes in a single one. Now that I've removed controlled values, I'm considering merging everything, but I'm still hesitating a bit due to the .selectors logic — the .context logic is pretty useful to have for everyone though.

@romgrk romgrk requested a review from michaldudak December 4, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Behind-the-scenes enhancement. Formerly called “core”. 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.

4 participants