question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[system] How to correctly merge multiple themes

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When composing themes (As described under “Theme Composition” https://mui.com/customization/theming/), typography.fontFamily in the second argument of createTheme is not applied.

Expected Behavior 🤔

typography.fontFamily is applied to each typography variant whether or not createTheme is called with a previous theme as the first argument.

Steps to Reproduce 🕹

https://codesandbox.io/s/mui-5-fontfamily-issue-lwfbf?file=/src/App.js

Steps:

  1. Create a theme in two steps as described under “Theme Composition” (https://mui.com/customization/theming/)
  2. In the second call to createTheme, set typography.fontFamily to anything other than the MUI default
  3. See that the custom fontFamily has not been correctly applied

Context 🔦

Workaround is to define typography.fontFamily in the top level theme. This is a valid work around for me because fontFamily it self does not depend on anything in the previous theme. However, this took me a while to diagnose and worries me that there may be other subtle issues with composing themes.

Your Environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mnajdovacommented, Oct 1, 2021

@MikeRawding right, your last solution is the correct one. Just make sure you are not doing this in the component, rather outside of it. I am closing this then.

1reaction
MikeRawdingcommented, Sep 30, 2021

I came up with this which only merges ThemeOptions objects. I still need to generate a true Theme at each step so I can access things like theme.breakpoints.up (which is not contained in ThemeOptions).

https://codesandbox.io/s/mui-5-fontfamily-issue-forked-59t7z?file=/src/App.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to combine Windows 7 themes
How to combine Windows 7 themes · 1. Step First of all open the Personalization Control Panel (Right-click on Desktop => Personalize) ·...
Read more >
Make Theme Switching Easy with UXPin Merge
Theme switcher cuts down the time to test different themes and change the styles of your design. See how to switch themes quickly...
Read more >
Combining themes in Windows 10
Themes are always unique-ish things. Do you mean edit them further? You can do that in the Settings application in the Personalization section....
Read more >
Merging Themes
Merging Themes. Sometimes it's useful to split a theme across multiple files, use a preset as the basis for a custom theme, or...
Read more >
How to Use Multiple Themes for Pages in WordPress
In this method, we'll use the Multiple Themes plugin to use 2 themes at once on your WordPress site. This method is best...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found