Skip to content

[Autocomplete] styled(Autocomplete) causes excessive TypeScript type instantiation, memory usage, and check time #49763

Done

Description

@hln-jhan

Search keywords

autocomplete, styled, styled autocomplete

Latest version

  • I have tested the latest version

Steps to reproduce

  1. Open the reproduction sandbox: https://stackblitz.com/github/mui/material-ui/tree/master/examples/material-ui-vite-ts?file=src%2FApp.tsx

  2. 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;
  3. Run the following command in the sandbox terminal:

    npx tsc -p tsconfig.app.json --noEmit --incremental false --extendedDiagnostics
  4. Observe the compiler diagnostics:

    Symbols:       1022338
    Instantiations:  818875
    Memory used:    568924K
    Check time:      9.807s
    
  5. Replace the declaration with plain Autocomplete:

    const StyledAutocomplete = Autocomplete;

    Remove the unused styled import, then rerun the same command.

  6. Observe the substantially reduced compiler overhead:

    Symbols:        136153
    Instantiations:   80954
    Memory used:     95861K
    Check time:      0.865s
    
  7. 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 Autocomplete assertion did not reduce the overhead.
  • Replacing styled(Autocomplete) with plain Autocomplete eliminated approximately 500 MiB of reported compiler memory usage.
  • Simplifying the component type passed into styled() using ComponentType<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-ts example (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.1
  • react: 19.3.1
  • react-dom: 19.3.1
  • @types/react: 19.3.0
  • typescript: 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: true
  • skipLibCheck: true
  • moduleResolution: "bundler"
  • noEmit: true

Benchmark command

npx tsc -p tsconfig.app.json --noEmit --incremental false --extendedDiagnostics

All standalone reproduction benchmarks were performed using the official MUI TypeScript Vite starter project.

Activity

  1. added
    status: waiting for maintainer
    on Nov 11, 2026
  2. added
    scope: autocomplete
    ai: needs-triage
    and removed
    status: waiting for maintainer
    on Nov 12, 2026
  3. github-actions commented on Nov 12, 2026

    @github-actions
    Contributor

    This looks like a real TypeScript performance problem with the documented pattern. The Autocomplete docs recommend exactly styled(Autocomplete)({...}) as typeof Autocomplete under Wrapping with styled(), 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 Autocomplete type declaration looks like now. Since getOptionValue support was added (#49078, cherry-picked to v9 in #49313), Autocomplete has several generic overloads. The last one is written specifically to serve wrappers such as styled() and React.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 before getOptionValue, 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-ts example and lists the edit and the tsc --extendedDiagnostics command, so the steps are clear.

    Workaround: your own workaround of passing Autocomplete as ComponentType<any> into styled() and then casting back to typeof Autocomplete keeps 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 that styled() no longer type-checks the wrapped component's props (for example, inside style callbacks that read props).

    Next steps

    • You: if you can, run the same benchmark with a release from before getOptionValue support, such as 9.4.x. That would show whether this is a regression. A trimmed --generateTrace output for the styled(Autocomplete) expression would also help.
    • Maintainers: decide whether to change the wrapper-facing Autocomplete overload or the styled() 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

  4. added
    type: bug
    and removed
    ai: needs-triage
    on Nov 12, 2026
  5. github-actions commented on Nov 26, 2026

    @github-actions
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai: triagedperformancescope: autocompletetype: bugtypescript

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions