Repository navigation
Description
Summary
createStyled iterates over all styleOverrides keys for every slot, then overridesResolver picks only the relevant ones. This is unnecessary work that compounds as components grow in slots and override keys. It also caused a class of runtime errors (ownerState undefined) that required per-component workarounds.
Current behavior
In createStyled.js, styleThemeOverrides does this:
for (const slotKey in styleOverrides) {
resolvedStyleOverrides[slotKey] = processStyle(
props,
styleOverrides[slotKey],
...
);
}
return overridesResolver(props, resolvedStyleOverrides);Every slot's styled component resolves all styleOverrides entries, then overridesResolver cherry-picks the needed ones.
Compounding cost — OutlinedInput example
OutlinedInput has 3 styled slots (Root, NotchedOutline, Input) and up to 15 styleOverrides keys (root, colorSecondary, focused, disabled, adornedStart, adornedEnd, error, sizeSmall, multiline, notchedOutline, input, inputSizeSmall, inputMultiline, inputAdornedStart, inputAdornedEnd).
With the current implementation, each render triggers:
- Slot
Root→ iterates 15 keys, uses ~10 - Slot
NotchedOutline→ iterates 15 keys, uses 1 - Slot
Input→ iterates 15 keys, uses ~7
Total: 45 processStyle calls per render, ~27 of which are discarded. If styleOverrides values are callbacks, each discarded call still executes the function with the wrong slot's props.
For TextField (which composes InputBase + OutlinedInput + InputLabel + FormHelperText), the waste multiplies further.
Runtime errors from the same root cause
Because every slot calls every styleOverrides callback with its own props, slots that don't receive ownerState crash when callbacks depend on it:
- [TextField]
MuiOutlinedInputcallback in styleOverrides sometimes passes ownerState as undefined #31982 —MuiOutlinedInputroot callback called byNotchedOutlineslot (no ownerState) - [Autocomplete ] Using
ownerStateis undefined instyleOverridesforAutocompleteon opening the options #43992 — Autocomplete styleOverrides crash on open - [Avatar] ownerState is undefined in styleOverrides when overriding Avatar styles #36223 — Avatar ownerState undefined
- [alert]
ownerStateisundefinedinstyleOverrideswhen providingactionprop #32799 — Alert ownerState undefined - [Tabs] ownerState is undefined in styleOverrides when variant is scrollable #38707 — Tabs ownerState undefined
These were fixed with per-component workarounds (passing ownerState to internal slots). The systemic fix was deferred because overridesResolver accesses multiple keys from the resolved object — changing it would be breaking.
Proposed behavior
Each slot should only resolve its own styleOverrides entry:
// Instead of iterating all keys:
const resolved = processStyle(props, styleOverrides[slot], ...);
return resolved;This requires changing overridesResolver to receive the resolved style directly instead of a map of all resolved styles. Components like InputBase that currently read multiple keys would need to be updated.
Context
- Existing TODO:
// TODO: v7 remove iteration and use resolveStyleArg(styleOverrides[slot]) directly - PR [system] Support variants in
theme.styleOverrides#40690 added the TODO - PR [OutlinedInput] Fix
ownerStateundefined in theme style overrides #33241 documented the breaking change blocker - oliviertassinari's analysis: [TextField]
MuiOutlinedInputcallback in styleOverrides sometimes passes ownerState as undefined #31982 (comment)
Search keywords:
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsTo process
Activity
linear commentedon Feb 16, 2026
MAT-1764
siriwatknp commentedon Feb 16, 2026
Breaking change impact assessment
What changes
Current
overridesResolversignature:Proposed: Each slot resolves only its own
styleOverrides[slot]entry.overridesResolvereither receives a single resolved style or is removed entirely.Casegorization
Case 1: Single-key resolvers (no migration needed) — ~52 components
These only access
styles[slotName]and work as-is with the new approach.The
defaultOverridesResolver(slot)increateStyled.jsalready produces this pattern. These are unaffected.Case 2: Multi-key resolvers on ROOT slots — ~40 components
These access
styles.rootplus conditional state/variant keys. This is the main migration surface.Pattern A — Conditional state keys (most common)
Affected:
Button,IconButton,Checkbox,Radio,Switch,Slider,TableCell,ListItem,ListItemButton,Fab,Badge,CircularProgress,LinearProgress,Typography,FormControlLabel,InputLabel,Tooltip,Tab,ToggleButton,Pagination, etc.Pattern B — Cross-slot keys via nested selectors
These root resolvers apply child slot styles using class selectors:
Affected:
Chip,Autocomplete,Rating,Switch(switchBase readsinput),ButtonGroup.Pattern C — Exported/shared resolvers
Affected:
InputBase(reused byOutlinedInput,FilledInput,Input).Case 3: Multi-key resolvers on NON-ROOT slots — ~15 slots
Affected:
Button(startIcon, endIcon),Chip(label),CircularProgress(circle, svg),LinearProgress(bar1, bar2),Rating(icon, label, decimal),Slider(thumb, track, rail, mark, markLabel, valueLabel),Autocomplete(popupIndicator, popper).Migration approach
For Case 2 & 3, the multi-key access is used to apply deprecated
styleOverrideskeys that map states/variants to separate keys (e.g.,styleOverrides.colorPrimary,styleOverrides.sizeSmall). In v7, these can be replaced by thevariantsAPI intheme.components:This would:
overridesResolveralways single-key → eliminate the iterationstyleOverrides(e.g.,colorPrimary,sizeSmall)External impact
This is a breaking change for users who define non-slot keys in
theme.components.Mui*.styleOverrides. A codemod could automate migration from state-based keys tovariants.siriwatknp commentedon Feb 16, 2026
Prerequisite: deprecate non-slot
styleOverrideskeysChecked
upgrade-to-v6.md,upgrade-to-v7.md, andmigrating-from-deprecated-apis.md— no deprecation exists for non-slotstyleOverrideskeys. The existing v6 deprecation is about composed CSS class names (e.g.,.MuiButton-textPrimary→.MuiButton-text.MuiButton-colorPrimary), not about thestyleOverridesobject keys themselves.What's deprecated (v6) vs what's not
Why this blocks the iteration fix
The multi-key
overridesResolverpattern exists to support these top-level keys. For example,Button's root resolver reads 9 keys (root,variant,variantColor,size,variantSize,colorInherit,disableElevation,fullWidth,loading). Removing the iteration without first deprecating these keys would silently break user themes.Suggested sequence
styleOverrideskeys with runtime warnings + migration guide pointing users tovariantsAPIstyleOverrides.colorPrimary: { ... }→styleOverrides.root.variants: [{ props: { color: 'primary' }, style: { ... } }]overridesResolverto single-key (next major)Yash-Tamboli commentedon Dec 3, 2026
Hi maintainers! I'd like to investigate the styleOverrides iteration overhead in createStyled and benchmark the proposed direct slot lookup approach. Is this available for contribution, and are there compatibility requirements I should follow?