Repository navigation
Description
Search keywords
autocomplete, styled, styled autocomplete
Latest version
- I have tested the latest version
Steps to reproduce
-
Open the reproduction sandbox: https://stackblitz.com/github/mui/material-ui/tree/master/examples/material-ui-vite-ts?file=src%2FApp.tsx
-
The project uses MUI Material 9.5.0 and TypeScript 5.9.3. In
src/App.tsx, the following declaration is active:const StyledAutocomplete = styled(Autocomplete)({}) as typeof Autocomplete;
-
Run the following command in the sandbox terminal:
npx tsc -p tsconfig.app.json --noEmit --incremental false --extendedDiagnostics -
Observe the compiler diagnostics:
Symbols: 1022338 Instantiations: 818875 Memory used: 568924K Check time: 9.807s -
Replace the declaration with plain Autocomplete:
const StyledAutocomplete = Autocomplete;
Remove the unused
styledimport, then rerun the same command. -
Observe the substantially reduced compiler overhead:
Symbols: 136153 Instantiations: 80954 Memory used: 95861K Check time: 0.865s -
Finally, restore
styled()but simplify the input component's type:import type { ComponentType } from 'react'; const StyledAutocomplete = styled( Autocomplete as ComponentType<any>, )({}) as unknown as typeof Autocomplete;
Rerun the command.
This produces approximately the same diagnostics as plain Autocomplete (95,792K memory, 80,954 instantiations, 0.879s checking time), while retaining the styled component and consumer-facing generic signature.
The issue reproduces using an empty styles object. The excessive compiler overhead appears to originate from passing Autocomplete's generic component type directly to styled(), rather than from the styles or the final type assertion.
Current behavior
Passing MUI's generic Autocomplete component directly into styled() causes a substantial increase in TypeScript compiler memory usage, type instantiations, symbol creation, and checking time.
In MUI's official material-ui-vite-ts example, a single styled(Autocomplete)({}) declaration with an empty styles object produces the following results compared with using Autocomplete directly:
Plain Autocomplete:
- Symbols: 136,153
- Type instantiations: 80,954
- Reported compiler memory: 95,861K
- Type-checking time: 0.865s
Styled Autocomplete:
- Symbols: 1,022,338
- Type instantiations: 818,875
- Reported compiler memory: 568,924K
- Type-checking time: 9.807s
This represents:
- 7.5× as many TypeScript symbols
- 10.1× as many type instantiations
- Approximately 462 MiB of additional reported compiler memory
- 11.3× longer type-checking time
The same behavior occurs in our larger Next.js application, where the original styled(Autocomplete) declaration results in approximately 491 MiB of additional reported compiler memory compared with a version that simplifies the component type passed into styled().
The overhead persists when the styles object is empty and when the final as typeof Autocomplete assertion is removed.
Simplifying the input component's type to ComponentType<any> eliminates nearly all the additional compiler overhead, indicating that the issue is related to the type information passed into styled() rather than the styling itself.
Expected behavior
Styling Autocomplete should not cause this degree of TypeScript type expansion, particularly when the styles object is empty.
The styled(Autocomplete) API should ideally allow the original component's generic signature to be retained without requiring users to erase the input component's type through an any assertion.
Context
We initially encountered this issue in a large Next.js 16 application using MUI Material 9.5.0, React 19, and TypeScript 5.9.3.
Our production build was failing during TypeScript checking with a JavaScript heap out-of-memory error. While investigating the compiler's memory consumption, we generated a TypeScript performance trace and identified a styled(Autocomplete) declaration as one of the most expensive expressions in the application.
The trace showed approximately 2.7 seconds spent checking this expression, primarily involving structural type comparisons.
Through controlled experiments, we established that:
- Removing the CSS rules did not reduce the compiler overhead.
- Removing the final
as typeof Autocompleteassertion did not reduce the overhead. - Replacing
styled(Autocomplete)with plainAutocompleteeliminated approximately 500 MiB of reported compiler memory usage. - Simplifying the component type passed into
styled()usingComponentType<any>produced the same improvement while preserving our original styling and consumer-facing generic signature.
In the production application, this workaround reduced reported TypeScript memory usage by approximately 19.4%, with 787,696 fewer symbols and 815,959 fewer type instantiations.
To determine whether the issue was specific to our application, we recreated it in MUI's official material-ui-vite-ts starter project.
The standalone reproduction showed an even more pronounced difference: styled(Autocomplete)({}) resulted in approximately 569 MB of reported compiler memory usage and 9.8 seconds of checking time, compared with approximately 96 MB and 0.9 seconds when using plain Autocomplete.
Using the simplified component type at the styled() boundary eliminated the additional overhead in the standalone reproduction as well.
This suggests a significant TypeScript performance issue involving the interaction between MUI's generic Autocomplete component and the styled() API, rather than an issue with our application-specific styles or component implementation.
Although the workaround resolves the excessive type expansion, it requires an any assertion at the styling boundary. Ideally, the public MUI types would support this use case without that compromise.
The original production build failure motivated this investigation; we have not yet established that the workaround alone resolves the production build's heap exhaustion.
I'm happy to provide the original TypeScript compiler trace if that would help investigate the underlying cause.
Your environment
System
- OS: macOS 26.3.1
- Node.js: 24.14.0
- npm: 11.21.1
Framework
- Next.js: 16.x (original application)
- Vite: MUI's official
material-ui-vite-tsexample (minimal reproduction)
Dependencies
@mui/material: 9.5.0@mui/system: 9.5.0@mui/styled-engine: 9.5.0@mui/types: 9.5.0@emotion/react: 11.14.0@emotion/styled: 11.14.1react: 19.3.1react-dom: 19.3.1@types/react: 19.3.0typescript: 5.9.3
Additional MUI dependencies in the original application
@mui/icons-material: 9.5.0@mui/x-data-grid: 9.17.0@mui/x-data-grid-premium: 9.17.0@mui/x-date-pickers: 9.17.0
TypeScript compiler settings
strict: trueskipLibCheck: truemoduleResolution: "bundler"noEmit: true
Benchmark command
npx tsc -p tsconfig.app.json --noEmit --incremental false --extendedDiagnosticsAll standalone reproduction benchmarks were performed using the official MUI TypeScript Vite starter project.
Activity
github-actions commentedon Nov 12, 2026
This looks like a real TypeScript performance problem with the documented pattern. The Autocomplete docs recommend exactly
styled(Autocomplete)({...}) as typeof Autocompleteunder Wrapping withstyled(), so an increase of about 10× in type instantiations and checking time for an empty style object isn't something you should have to work around.Your numbers agree with what the
Autocompletetype declaration looks like now. SincegetOptionValuesupport was added (#49078, cherry-picked to v9 in #49313),Autocompletehas several generic overloads. The last one is written specifically to serve wrappers such asstyled()andReact.memo(), and its props type is a large intersection plus conditional types.styled()has to check that generic signature against its own component constraints and then build its style and prop types from the result, so that one overload may account for much of the cost. Your report doesn't include a comparison with a release from beforegetOptionValue, so it's still unknown whether this is new or just got worse.I haven't run your StackBlitz reproduction. It links to the
material-ui-vite-tsexample and lists the edit and thetsc --extendedDiagnosticscommand, so the steps are clear.Workaround: your own workaround of passing
Autocomplete as ComponentType<any>intostyled()and then casting back totypeof Autocompletekeeps the generic signature that consumers see. That signature comes only from the final cast, so you lose nothing compared with the documented pattern. The difference is thatstyled()no longer type-checks the wrapped component's props (for example, inside style callbacks that read props).Next steps
getOptionValuesupport, such as 9.4.x. That would show whether this is a regression. A trimmed--generateTraceoutput for thestyled(Autocomplete)expression would also help.Autocompleteoverload or thestyled()component typings to reduce this cost, keeping the existing wrapper type tests passing.Agent-generated diagnosis; conclusions have not been independently verified. Workflow run.
🤖 Triage · Claude Code · claude-opus-5-5 · high effort · 19 turns · 1m17s · $0.38 · run
github-actions commentedon Nov 26, 2026
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.
@hln-jhan Thanks again for creating this issue! If you have a moment, we would love to hear your thoughts on how we handled it with this short feedback form.