Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[system] Prevent nested non-vars theme inheritance #45545

Merged
merged 3 commits into from
Mar 12, 2025

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Mar 11, 2025

closes #45544

Root cause

Nested ThemeProvider with non-cssvars theme throws an error when the upper theme is css vars.

The use case is the MUI docs where css vars theme comes from the branding theme and nested theme comes from customization demo.

<ThemeProvider theme={cssVarsTheme}>
  <ThemeProvider theme={nonCssVarsTheme}> // the theme passed to context gets `vars` from the above theme
    // if the component access to the new color added to `nonCssVarsTheme` but not in `cssVarsTheme`,
    // the error occurs.
    <Button color="ochre">

For full details: #45544 (comment)

Solution

Set vars: null to the theme when the theme input does not have vars, so that it does not inherit vars from the upper theme.

@siriwatknp siriwatknp added the package: system Specific to @mui/system label Mar 11, 2025
@mui-bot
Copy link

mui-bot commented Mar 11, 2025

Netlify deploy preview

https://deploy-preview-45545--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 632bca4

@siriwatknp siriwatknp added the needs cherry-pick The PR should be cherry-picked to master after merge label Mar 11, 2025
@siriwatknp siriwatknp added needs cherry-pick The PR should be cherry-picked to master after merge and removed needs cherry-pick The PR should be cherry-picked to master after merge labels Mar 12, 2025
@siriwatknp siriwatknp enabled auto-merge (squash) March 12, 2025 07:30
@siriwatknp siriwatknp merged commit 9ab5dcf into mui:master Mar 12, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs cherry-pick The PR should be cherry-picked to master after merge package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ThemeProvider] Error when upper theme is CSS variables but nested theme is not
3 participants