useTheme
returns a new reference every time if any provided theme has cssVariables: true
#44555
Labels
customization: theme
Centered around the theming features
Steps to reproduce
Steps:
RerenderedComponent
rerenders, and that the console prints a diff between the theme provided by theuseTheme
hookIf you set both
cssVariables
props tofalse
, it doesn't rerender. If either theme hascssVariables: true
it rerenders. It seems like the unstable properties are always thespacing
andunstable_sx
functions - all other props are deeply equal (though they might have new references as well)Current behavior
useTheme
will return a new reference - even if the theme hasn't changed - if any theme in a nested hierarchy hascssVariables: true
. This causes memoized components/functions to be reevaluated even if nothing on the theme has been explicitly modified.Expected behavior
The theme reference returned from
useTheme
should be stable, and only change if the theme itself has changed.Context
I want to be able to pass the output from
useTheme
to memoized components/useEffect
calls and not have them reevaluate unless something has actually changed.Your environment
npx @mui/envinfo
Search keywords: cssVariables, ThemeProvider, useTheme
The text was updated successfully, but these errors were encountered: