[POC] Improve TypeScript Theme Components Performance #47013
+162
−37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Breaking Change for Type Imports: Deprecated type utilities (
Components
,ComponentsProps
,ComponentsOverrides
,ComponentsVariants
,adaptV4Theme
) have been moved to a new@mui/material/stylesDeprecated
entry point. Users directly importing these types must update their imports.🎯 Main Purpose
This PR resolves critical TypeScript compilation performance issues caused by circular type dependencies in the theme system. The previous
Components<Omit<Theme, 'components'>>
pattern triggered excessive type instantiations (~7xxk), leading to slow compilation, high memory usage, and degraded IDE performance.🔧 Key Changes
Type System Refactoring
Components<Omit<Theme, 'components'>>
with a simpleThemeComponents
interfaceCreateThemeComponent
Utility: Added generic type helper for type-safe component theme customizationCode Organization
stylesDeprecated
Directory: Moved deprecated APIs (Components
,ComponentsProps
,ComponentsOverrides
,ComponentsVariants
,adaptV4Theme
) topackages/mui-material/src/stylesDeprecated/
@mui/material/stylesDeprecated
instead of@mui/material/styles
Performance Testing Infrastructure
perf-test
Directory: Added TypeScript performance diagnostics tooling📁 Files Affected
Core Type System (6 files)
packages/mui-material/src/styles/createTheme.ts
- Export new typespackages/mui-material/src/styles/createThemeFoundation.ts
- AddThemeComponents
interfacepackages/mui-material/src/styles/createThemeNoVars.d.ts
- AddCreateThemeComponent
type, simplify Theme interfacepackages/mui-material/src/styles/createThemeWithVars.d.ts
- Remove redundantcomponents
fromCssVarsThemeOptions
packages/mui-material/src/styles/useThemeProps.d.ts
- UseThemeComponents
instead ofComponents<>
packages/mui-material/src/styles/index.d.ts
- Remove deprecated exports, add new typesDeprecated Types Migration (6 files moved + 1 new)
Moved to
stylesDeprecated/
:adaptV4Theme.d.ts
,adaptV4Theme.js
,adaptV4Theme.test.js
components.ts
,overrides.ts
,props.ts
,variants.ts
New:
packages/mui-material/src/stylesDeprecated/index.ts
- Consolidated exportsPackage Updates (5 files)
packages/mui-lab/src/themeAugmentation/components.ts
- Module path updatepackages/mui-lab/src/themeAugmentation/overrides.ts
- Module path updatepackages/mui-lab/src/themeAugmentation/props.ts
- Module path updatepackages/mui-docs/src/branding/brandingTheme.ts
- ExtendThemeComponents
with deprecatedComponents<>
packages/mui-material/src/Button/Button.d.ts
- AddButtonTheme
exportInternal Updates (2 files)
packages/mui-material/src/DefaultPropsProvider/DefaultPropsProvider.tsx
- Update import pathpackages/mui-material/src/locale/utils/LocaleTextApi.ts
- Update import pathPerformance Testing (3 new files)
packages/mui-material/perf-test/README.md
- Testing guidepackages/mui-material/perf-test/test-createTheme.ts
- Performance test casepackages/mui-material/perf-test/tsconfig.json
- Test configuration🚀 Impact
Performance Improvements
Migration Required
Users directly importing these types must update their imports:
Module Augmentation Pattern
For packages extending MUI components (like
@mui/lab
):💡 Implementation Notes
New Component Theme Export Pattern
The
Button
component demonstrates the new pattern for exporting component-specific theme types:Performance Testing Workflow
Note
The performance testing infrastructure helps maintainers monitor TypeScript compilation metrics and identify performance regressions early.
🔍 Review Focus Areas
CreateThemeComponent
provides adequate type safety for component customizationResult
Before:
After:
Test
Follow the packages/mui-material/perf-test/README.md to test this PR.