Skip to content

[Autocomplete] Lazily derive the initial input value - #49057

Open
OskarEichler wants to merge 1 commit into
mui:masterfrom
OskarEichler:codex/mui-autocomplete-lazy-initial-value
Open

[Autocomplete] Lazily derive the initial input value#49057
OskarEichler wants to merge 1 commit into
mui:masterfrom
OskarEichler:codex/mui-autocomplete-lazy-initial-value

Conversation

@OskarEichler

Copy link
Copy Markdown
Contributor

What changed

  • Derives the mount-only initial input value with a lazy state initializer instead of evaluating the useRef argument on every render.
  • Avoids an otherwise unused getOptionLabel call on every production render (two calls per Strict Mode render cycle).
  • No public API or rendered-value behavior changes.

useRef(expression) preserves the first result but still evaluates expression during every render. A lazy state initializer matches the existing mount-only contract.

Verification

  • External render/rerender control against the base: label calls increased from 6 to 11.
  • The same control after the fix: label calls increased from 6 to 9, removing the two mount-only recomputations under Strict Mode.
  • pnpm test:unit run useAutocomplete --project 'node:@mui/material'
  • pnpm -F @mui/material typescript
  • Targeted ESLint and Prettier checks.
  • Full pnpm release:build.
  • Full Material Node unit suite: 179 passed / 4 skipped files; 4,712 passed / 759 skipped tests.

The browser test project was not run locally because Playwright Chromium is not installed in this checkout.

Contribution

  • I have followed the contributing guide.

This change and PR description were prepared with OpenAI Codex, then self-reviewed and verified locally. No independent human review has occurred yet.

@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-49057--material-ui.netlify.app/
QR code for https://deploy-preview-49057--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) ▼-1B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


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

@zannager zannager added the scope: autocomplete Changes related to the autocomplete. This includes ComboBox. label Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: autocomplete Changes related to the autocomplete. This includes ComboBox.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants