Skip to content

[all components] Do not memoize the state when not needed - #3812

Merged
flaviendelangle merged 2 commits into
mui:masterfrom
flaviendelangle:remove-state-memoization
Jan 23, 2026
Merged

flaviendelangle merged 2 commits into
mui:masterfrom
flaviendelangle:remove-state-memoization

Conversation

@flaviendelangle

Copy link
Copy Markdown
Member

Closes #3495

@flaviendelangle flaviendelangle self-assigned this Jan 21, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jan 21, 2026 •

Copy link
Copy Markdown
  • vite-css-base-ui-example

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

commit: b5ec987

@mui-bot

mui-bot commented Jan 21, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react ▼-3.01KB(-0.72%) ▼-725B(-0.54%)

Details of bundle changes


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

@netlify

netlify Bot commented Jan 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit b5ec987
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69733f7587393800085438f8
😎 Deploy Preview https://deploy-preview-3812--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
flaviendelangle force-pushed the remove-state-memoization branch from 7aa2c61 to 15600c6 Compare January 21, 2026 14:07
@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. performance scope: all components Widespread work has an impact on almost all components. labels Jan 21, 2026
@flaviendelangle
flaviendelangle marked this pull request as ready for review January 21, 2026 14:11
@flaviendelangle

Copy link
Copy Markdown
Member Author

@greptileai

@greptile-apps

greptile-apps Bot commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Removed unnecessary useMemo wrappers from state objects across all components. The state objects passed to useRenderElement() were being memoized but never actually benefited from memoization since data attributes are generated on every render and render props are called on every render. This change improves performance by eliminating the overhead of dependency comparison on every render.

  • Converted 101 component files from React.useMemo(() => ({ ...state }), [deps]) to plain object literals { ...state }
  • Added missing JSDoc comments for state properties in several components (RadioGroup, ToggleGroup, NavigationMenuPopup) to improve type documentation
  • Updated test file to reflect the pattern change
  • Net reduction of 244 lines of code

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are purely a performance optimization that removes unnecessary memoization. The transformation is mechanical and consistent across all files, changing only the state object creation pattern while preserving identical runtime behavior. The test updates confirm the pattern works correctly. Added JSDoc comments improve documentation without affecting functionality.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/button/Button.tsx Removed unnecessary useMemo wrapper around state object
packages/react/src/radio-group/RadioGroup.tsx Removed useMemo wrapper, added missing JSDoc for required property in interface
packages/react/src/toggle-group/ToggleGroup.tsx Removed useMemo wrapper, added JSDoc for multiple and orientation properties
packages/react/src/navigation-menu/popup/NavigationMenuPopup.tsx Removed useMemo wrapper, added JSDoc for side, align, and anchorHidden properties, added required import
packages/react/src/utils/useRenderElement.test.tsx Updated test to reflect removal of useMemo wrapper in state creation

@atomiks atomiks left a comment

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.

The only case I can think of memo being used is:

<Component 
  render={
    (props, state) => <MemoComp {...props} state={state} />
  } 
/>

Though individual props are unmemoized already (notably, event handlers), so I don't think this was relevant to begin with?

@flaviendelangle

Copy link
Copy Markdown
Member Author

The only case I can think of memo being used is:

Yes, that's the only actual difference in behavior I could find, but I think it's not one we should optimize for

@flaviendelangle
flaviendelangle merged commit 48c6258 into mui:master Jan 23, 2026
@flaviendelangle
flaviendelangle deleted the remove-state-memoization branch January 23, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance scope: all components Widespread work has an impact on almost all components. 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.

[all components] Do not memoize the state object before passing it to useRenderElement()

3 participants