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.

MuiThemeProvider removes extra fields from theme

See original GitHub issue
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

As with @material-ui/core@^3 the extra theme fields ( i.e. colors ) should not be removed

Current Behavior 😯

Any extra fields are removed after the created theme is passed to MuiThemeProvider and do not reach theme consumers.

Steps to Reproduce 🕹

Link:

  1. git clone https://github.com/mateja176/react-hot-starter
  2. cd react-hot-starter
  3. git checkout material-ui-4
  4. npm install
  5. npm start
  6. open console and compare PROVIDED theme and CONSUMED theme values

Context 🔦

Extend theme with additional color properties, i.e. success color for snackbar.

Your Environment 🌎

Tech Version
Material-UI v4.1.3
React Scripts 3.0.1
Browser Chrome
TypeScript 3.5.1
etc.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
eps1loncommented, Jul 6, 2019

@mateja176 Top of your console includes

It looks like there are several instances of @material-ui/styles initialized in this application. This may cause theme propagation issues, broken class names and makes your application bigger without a good reason.

See https://material-ui.com/r/styles-instance-warning for more info.

npm included multiple versions even though npm ls resulted in

├─┬ @material-ui/core@4.1.3
│ └── @material-ui/styles@4.1.2 
└── @material-ui/styles@4.1.2 

It shouldn’t install two versions. If I remove node_modules/@material-ui/core/node_modules/@material-ui/styles everything works as expected. Try regenerating your package-lock or try yarn.

If this doesn’t help please ask the question on stackoverflow and link it from here so that we can continue this conversation.

0reactions
mateja176commented, Jul 6, 2019

@eps1lon On point, thank you so much! All that was required is:

rm package-lock.json
npm i

And @material-ui/styles@4.1.2 is now deduped

├─┬ @material-ui/core@4.1.3
│ ├── @material-ui/styles@4.1.2 deduped
├─┬ @material-ui/styles@4.1.2

My apologies, this was not directly related to @material-ui.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change custom theme Material-UI - Stack Overflow
Wrap the child components inside a MuiThemeProvider and pass a createMuiTheme object to it as a theme property value.
Read more >
Separate themes for Mui and styled components · Issue #28979
Since my old theme has fields with the same keys as the one generated ... as MuiThemeProvider, Theme } from '@mui/material/styles'; import ...
Read more >
Theming - Material UI - MUI
WARNING: theme.vars is a private field used for CSS variables support. Please use another name for a custom object. responsiveFontSizes(theme, options) => theme....
Read more >
Theming with React and MUI - Welcome, Developer
Learn how to create custom themes to React app using MUI. ... Go to src/App.tsx and remove everything we don't need: src/App.tsx.
Read more >
Material UI Tutorial #6 - Custom Themes - YouTube
Hey gang, in this material UI tutorial we'll take a look at how to create custom themes (colours, spacing, typography, etc) for your ......
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