Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
03e0443
add perf-test
siriwatknp Oct 10, 2025
4d89fcf
migrate to stylesOptimized
siriwatknp Oct 10, 2025
1e958dd
move Theme to stylesOptimized
siriwatknp Oct 10, 2025
054d4e1
mirror exports part 1
siriwatknp Oct 13, 2025
0607504
finish mirror exports
siriwatknp Oct 13, 2025
e69ff50
rexport CssThemeVariables
siriwatknp Oct 13, 2025
f129fe4
move to stylesOptimized
siriwatknp Oct 13, 2025
35135b1
reexport Theme with augmenting ThemeComponents
siriwatknp Oct 14, 2025
ccebdd4
fix lint
siriwatknp Oct 14, 2025
08993f2
Merge branch 'master' of github.com:mui/material-ui into fix/types-th…
siriwatknp Oct 14, 2025
e6f3e54
fix lint
siriwatknp Oct 14, 2025
e050e50
export component theme
siriwatknp Oct 14, 2025
7f0b2f8
finish ComponentTheme
siriwatknp Oct 14, 2025
3307ce5
fix missing imports
siriwatknp Oct 14, 2025
43199f8
fix: make styleOverrides record partial
siriwatknp Oct 20, 2025
9ebbead
add ts-performance test
siriwatknp Oct 22, 2025
b6befb4
remove temp test
siriwatknp Oct 22, 2025
8d062e8
update docs
siriwatknp Oct 22, 2025
7b1a6f7
Merge branch 'master' of github.com:mui/material-ui into fix/types-th…
siriwatknp Oct 22, 2025
fb57fba
update lock file
siriwatknp Oct 22, 2025
0bb8580
fix non-breaking space
siriwatknp Oct 22, 2025
5f769c0
pnpm dedupe
siriwatknp Oct 22, 2025
6a50195
fix themeCssVarsAugmentation to augment stylesOptimized
siriwatknp Oct 22, 2025
28befd2
export lab component theme types
siriwatknp Oct 22, 2025
61ac3e1
make the component theme optional
siriwatknp Oct 27, 2025
5d617a3
switch to esm
siriwatknp Oct 30, 2025
0a7f14a
Merge branch 'master' of github.com:mui/material-ui into fix/types-th…
siriwatknp Nov 6, 2025
33d10fb
restore
siriwatknp Nov 6, 2025
a59b2a8
run pnpm install
siriwatknp Nov 6, 2025
4262bcc
fix missing import
siriwatknp Nov 6, 2025
89da810
restore
siriwatknp Nov 6, 2025
73a5ac6
add release:test
siriwatknp Nov 6, 2025
17eb6b0
apply suggestion
siriwatknp Nov 6, 2025
560287e
add codemod
siriwatknp Nov 6, 2025
3b62912
Merge branch 'master' into fix/types-theme-components2
siriwatknp Nov 10, 2025
c9f76a5
Merge branch 'master' of github.com:mui/material-ui into fix/types-th…
siriwatknp Nov 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ jobs:
- run:
name: Validate type declarations
command: pnpm validate-declarations
- run:
name: Run tests that depend on built packages
command: pnpm -r run release:test
- run:
name: Analyze exported typescript
command: pnpm test:attw
Expand Down
45 changes: 45 additions & 0 deletions docs/data/material/guides/typescript/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,48 @@
// your custom styles go here
}) as typeof Button;
```

## Performance optimizations

When building a custom theme, Material UI provides automatic autocompletion and type checking for all tokens and components.
However, this comes at the cost of some performance overhead because TypeScript has to instantiate types for all components and their variants. This can lead to slower compilation times, especially in large codebase with intensive theme customization.

Starting from v7.4.0, Material UI offers an optimized path that significantly reduces the type instantiation overhead.
This path mirrors the exports from `@mui/material/styles` without the automatic inclusion of all component types.

Follow the steps below to enable the optimized path in your project:

1. Update all of the imports in your codebase from.

```diff
-'@mui/material/styles';
+'@mui/material/stylesOptimized';
```

:::warning
The optimization will not take effect if there is a single import from the `@mui/material/styles`.

Check warning on line 88 in docs/data/material/guides/typescript/typescript.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.Will] Avoid using 'will'. Raw Output: {"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/data/material/guides/typescript/typescript.md", "range": {"start": {"line": 88, "column": 18}}}, "severity": "WARNING"}
:::

2. Use module augmentation to explicitly include the component types to the theme.

```ts
import { createTheme } from '@mui/material/stylesOptimized';

import { ButtonTheme } from '@mui/material/Button';
import { TextFieldTheme } from '@mui/material/TextField';

declare module '@mui/material/stylesOptimized' {
interface ThemeComponents extends ButtonTheme, TextFieldTheme {}
}

const theme = createTheme({
components: {
MuiButton: {
// type-safe and autocompletion enabled
},
MuiTextField: {
// type-safe and autocompletion enabled
},
},
});
```
13 changes: 13 additions & 0 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,19 @@ npx @mui/codemod@latest deprecations/typography-props <path>

### v7.0.0

#### `styles-optimized`

```bash
npx @mui/codemod@latest v7.0.0/styles-optimized <path>
```

Replace the import of `@mui/material/styles` with `@mui/material/stylesOptimized` to optimize the TypeScript instantiation for theme components.

```diff
- import { createTheme } from '@mui/material/styles';
+ import { createTheme } from '@mui/material/stylesOptimized';
```

#### `theme-color-functions`

```bash
Expand Down
11 changes: 11 additions & 0 deletions packages/mui-codemod/src/v7.0.0/styles-optimized/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createTheme } from '@mui/material/styles';

// declare module '@mui/material/styles' {
// interface Theme {
// custom: {
// color: string;
// };
// }
// }

createTheme();
11 changes: 11 additions & 0 deletions packages/mui-codemod/src/v7.0.0/styles-optimized/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createTheme } from '@mui/material/stylesOptimized';

// declare module '@mui/material/stylesOptimized' {
// interface Theme {
// custom: {
// color: string;
// };
// }
// }

createTheme();
1 change: 1 addition & 0 deletions packages/mui-codemod/src/v7.0.0/styles-optimized/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './styles-optimized';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @param {import('jscodeshift').FileInfo} file
* @param {import('jscodeshift').API} api
*/
export default function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);

const printOptions = {
quote: 'single',
};

root
.find(j.ImportDeclaration)
.filter((path) => path.node.source.value === '@mui/material/styles')
.forEach((path) => {
path.node.source.value = '@mui/material/stylesOptimized';
});

return root
.toSource(printOptions)
.replace(
/declare module "@mui\/material\/styles"/g,
'declare module "@mui/material/stylesOptimized"',
)
.replace(
/declare module '@mui\/material\/styles'/g,
"declare module '@mui/material/stylesOptimized'",
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import path from 'path';
import { expect } from 'chai';
import jscodeshift from 'jscodeshift';
import transform from './index';
import readFile from '../../util/readFile';

function read(fileName) {
return readFile(path.join(__dirname, fileName));
}

describe('@mui/codemod', () => {
describe('v7.0.0', () => {
describe('styles-optimized', () => {
it('transforms as needed', () => {
const actual = transform(
{
source: read('./actual.js'),
path: require.resolve('./actual.js'),
},
{ jscodeshift },
{},
);

const expected = read('./expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});

it('should be idempotent', () => {
const actual = transform(
{
source: read('./expected.js'),
path: require.resolve('./expected.js'),
},
{ jscodeshift },
{},
);

const expected = read('./expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
});
});
});
6 changes: 4 additions & 2 deletions packages/mui-lab/src/Masonry/Masonry.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ResponsiveStyleValue, SxProps } from '@mui/system';
import { OverridableComponent, OverrideProps } from '@mui/material/OverridableComponent';
import { Theme } from '@mui/material/styles';
import { MasonryClasses } from './masonryClasses';
import { Theme, CreateThemeComponent } from '@mui/material/stylesOptimized';
import { MasonryClasses, MasonryClassKey } from './masonryClasses';

export interface MasonryOwnProps {
/**
Expand Down Expand Up @@ -69,4 +69,6 @@ export type MasonryProps<
AdditionalProps = {},
> = OverrideProps<MasonryTypeMap<AdditionalProps, RootComponent>, RootComponent>;

export type MasonryTheme = CreateThemeComponent<MasonryClassKey, MasonryProps>;

export default Masonry;
6 changes: 4 additions & 2 deletions packages/mui-lab/src/TabPanel/TabPanel.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { InternalStandardProps as StandardProps } from '@mui/material/internal';
import { Theme } from '@mui/material/styles';
import { CreateThemeComponent, Theme } from '@mui/material/stylesOptimized';
import { SxProps } from '@mui/system';
import { TabPanelClasses } from './tabPanelClasses';
import { TabPanelClasses, TabPanelClassKey } from './tabPanelClasses';

export interface TabPanelProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>> {
/**
Expand All @@ -29,6 +29,8 @@ export interface TabPanelProps extends StandardProps<React.HTMLAttributes<HTMLDi
keepMounted?: boolean;
}

export type TabPanelTheme = CreateThemeComponent<TabPanelClassKey, TabPanelProps>;

/**
*
* Demos:
Expand Down
8 changes: 6 additions & 2 deletions packages/mui-material/src/Accordion/Accordion.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { Theme } from '../styles';
import { CreateThemeComponent, Theme } from '../stylesOptimized';
import { TransitionProps } from '../transitions/transition';
import { AccordionClasses } from './accordionClasses';
import { AccordionClasses, AccordionClassKey } from './accordionClasses';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { ExtendPaperTypeMap, PaperProps } from '../Paper/Paper';
import { CreateSlotsAndSlotProps, SlotComponentProps, SlotProps } from '../utils/types';
Expand Down Expand Up @@ -157,4 +157,8 @@ export type AccordionProps<

export interface AccordionOwnerState extends AccordionProps {}

export type AccordionTheme = {
MuiAccordion?: CreateThemeComponent<AccordionClassKey, AccordionProps>;
};

export default Accordion;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { Theme } from '../styles';
import { CreateThemeComponent, Theme } from '../stylesOptimized';
import { InternalStandardProps as StandardProps } from '../internal';
import { AccordionActionsClasses } from './accordionActionsClasses';
import { AccordionActionsClasses, AccordionActionsClassKey } from './accordionActionsClasses';

export interface AccordionActionsProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>> {
/**
Expand Down Expand Up @@ -35,3 +35,7 @@ export interface AccordionActionsProps extends StandardProps<React.HTMLAttribute
* - [AccordionActions API](https://mui.com/material-ui/api/accordion-actions/)
*/
export default function AccordionActions(props: AccordionActionsProps): React.JSX.Element;

export type AccordionActionsTheme = {
MuiAccordionActions?: CreateThemeComponent<AccordionActionsClassKey, AccordionActionsProps>;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { Theme } from '../styles';
import { CreateThemeComponent, Theme } from '../stylesOptimized';
import { InternalStandardProps as StandardProps } from '../internal';
import { AccordionDetailsClasses } from './accordionDetailsClasses';
import { AccordionDetailsClasses, AccordionDetailsClassKey } from './accordionDetailsClasses';

export interface AccordionDetailsProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>> {
/**
Expand Down Expand Up @@ -30,3 +30,7 @@ export interface AccordionDetailsProps extends StandardProps<React.HTMLAttribute
* - [AccordionDetails API](https://mui.com/material-ui/api/accordion-details/)
*/
export default function AccordionDetails(props: AccordionDetailsProps): React.JSX.Element;

export type AccordionDetailsTheme = {
MuiAccordionDetails?: CreateThemeComponent<AccordionDetailsClassKey, AccordionDetailsProps>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { SxProps } from '@mui/system';
import { ButtonBaseProps, ExtendButtonBase, ExtendButtonBaseTypeMap } from '../ButtonBase';
import { OverrideProps } from '../OverridableComponent';
import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';
import { Theme } from '../styles';
import { AccordionSummaryClasses } from './accordionSummaryClasses';
import { CreateThemeComponent, Theme } from '../stylesOptimized';
import { AccordionSummaryClasses, AccordionSummaryClassKey } from './accordionSummaryClasses';

export interface AccordionSummarySlots {
/**
Expand Down Expand Up @@ -108,4 +108,8 @@ export type AccordionSummaryProps<
component?: React.ElementType;
};

export type AccordionSummaryTheme = {
MuiAccordionSummary?: CreateThemeComponent<AccordionSummaryClassKey, AccordionSummaryProps>;
};

export default AccordionSummary;
8 changes: 6 additions & 2 deletions packages/mui-material/src/Alert/Alert.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as React from 'react';
import { OverridableStringUnion } from '@mui/types';
import { SxProps } from '@mui/system';
import { SvgIconProps } from '../SvgIcon';
import { Theme } from '../styles';
import { CreateThemeComponent, Theme } from '../stylesOptimized';
import { InternalStandardProps as StandardProps } from '../internal';
import { IconButtonProps } from '../IconButton';
import { PaperProps } from '../Paper';
import { AlertClasses } from './alertClasses';
import { AlertClasses, AlertClassKey } from './alertClasses';
import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';

export type AlertColor = 'success' | 'info' | 'warning' | 'error';
Expand Down Expand Up @@ -203,3 +203,7 @@ export interface AlertOwnerState extends AlertProps {}
* - inherits [Paper API](https://mui.com/material-ui/api/paper/)
*/
export default function Alert(props: AlertProps): React.JSX.Element;

export type AlertTheme = {
MuiAlert?: CreateThemeComponent<AlertClassKey, AlertProps>;
};
8 changes: 6 additions & 2 deletions packages/mui-material/src/AlertTitle/AlertTitle.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { Theme } from '../styles';
import { CreateThemeComponent, Theme } from '../stylesOptimized';
import { TypographyProps } from '../Typography';
import { AlertTitleClasses } from './alertTitleClasses';
import { AlertTitleClasses, AlertTitleClassKey } from './alertTitleClasses';

export interface AlertTitleProps extends TypographyProps<'div'> {
/**
Expand Down Expand Up @@ -31,3 +31,7 @@ export interface AlertTitleProps extends TypographyProps<'div'> {
* - inherits [Typography API](https://mui.com/material-ui/api/typography/)
*/
export default function AlertTitle(props: AlertTitleProps): React.JSX.Element;

export type AlertTitleTheme = {
MuiAlertTitle?: CreateThemeComponent<AlertTitleClassKey, AlertTitleProps>;
};
8 changes: 6 additions & 2 deletions packages/mui-material/src/AppBar/AppBar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as React from 'react';
import { SxProps } from '@mui/system';
import { OverridableStringUnion } from '@mui/types';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { PropTypes, Theme } from '../styles';
import { AppBarClasses } from './appBarClasses';
import { CreateThemeComponent, PropTypes, Theme } from '../stylesOptimized';
import { AppBarClasses, AppBarClassKey } from './appBarClasses';
import { ExtendPaperTypeMap } from '../Paper/Paper';

export interface AppBarPropsColorOverrides {}
Expand Down Expand Up @@ -84,4 +84,8 @@ export type AppBarProps<
component?: React.ElementType;
};

export type AppBarTheme = {
MuiAppBar?: CreateThemeComponent<AppBarClassKey, AppBarProps>;
};

export default AppBar;
11 changes: 9 additions & 2 deletions packages/mui-material/src/Autocomplete/Autocomplete.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { OverridableStringUnion } from '@mui/types';
import { Theme } from '../styles';
import { CreateThemeComponent, Theme } from '../stylesOptimized';
import { InternalStandardProps as StandardProps } from '../internal';
import { IconButtonProps } from '../IconButton';
import { ChipProps, ChipTypeMap } from '../Chip';
Expand All @@ -17,7 +17,7 @@ import useAutocomplete, {
UseAutocompleteProps,
AutocompleteFreeSoloValueMapping,
} from '../useAutocomplete';
import { AutocompleteClasses } from './autocompleteClasses';
import { AutocompleteClasses, AutocompleteClassKey } from './autocompleteClasses';
import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';

export interface AutocompletePaperSlotPropsOverrides {}
Expand Down Expand Up @@ -421,3 +421,10 @@ export default function Autocomplete<
>(
props: AutocompleteProps<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>,
): React.JSX.Element;

export type AutocompleteTheme = {
MuiAutocomplete?: CreateThemeComponent<
AutocompleteClassKey,
AutocompleteProps<any, any, any, any>
>;
};
Loading
Loading