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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
When customizing breakpoints with createMuiTheme, only a shallow merged value is created #16563
Comments
value
is created
value
is created
@eps1lon Sorry my bad, that wasn't the most updated version of codesandbox. I have updated it already; and as you can see from the devtool, the values object only contains one key (xl). I believe the problem isn't about the use of withStyles or not. It's about the However, if you remove the theme provider and use the default theme, it works. |
Now I understand. You want the breakpoints to be merged instead of replaced. I think we should come up with a better strategy. If we implement your expected behavior it's easy to pass in non-sensical breakpoints where a semantically larger breakpoint is numericaly smaller e.g. xl: 200. So I'm not sure if this is a docs issue or if we should support it. Until then I'd recommend using const customStyle = {
breakpoints: {
values: {
+ xs: 0,
+ sm: 600,
+ md: 960,
+ lg: 1280,
xl: 1300,
}
}
};
|
Yes, you do make sense. If it will be supported in the future, maybe throw an error/warning when the numbers don't make sense? For now maybe it will be better to document this in more detail to avoid naive users like me. |
@eps1lon I was hit by this problem at Onepixel 8 months ago. I agree, we should and we can do better. I might require a BC. |
But honestly looking at this now I'd rather have a warning that there are missing breakpoints over merging breakpoints. Every time you look at this code you also have to know default values. Yes this is opinionated but it's really not that hard to copy 4 values. |
There is an opportunity for a warning too 馃憤 |
When customizing breakpoints with createMuiTheme, only a shallow merged value is created
Expected Behavior 馃
When providing a customized theme object,
createMuiTheme
should deep merge it.Current Behavior 馃槸
createMuiTheme
only shallow mergesbreakpoints.value
.Steps to Reproduce 馃暪
Link: https://codesandbox.io/s/jovial-thunder-hgw6u
Context 馃敠
I am sure this is not new in v4 - not sure if this is the intended behaviour, however, when I tried to custom breakpoints by providing a customized theme object to
createMuiTheme
like this:I thought
createMuiTheme
will deep merge the customized theme object with the default values so I thought for the rest of the keys not provided it will fallback to use the default values of:However I bumped into some bugs and after digging into the source code, I found out that when
createMuiTheme
callscreateBreakpoints
it overrides thevalue
key insidebreakpoints
completely without merging the respective values.Therefore, when the display size falls in an undefined value, the withWidth HOC returns some invalid value as well, thus breaking some features relying on
withWidth
such as<Hidden />
.Is a deep merge for
createBreakpoints
not implemented due to performance issues? If so, maybe it will be a good idea to document it better, instead of sayingbecause
sounds like a deep merge of all keys to me. On top of that the implementation details inside
createMuiTheme
indeed deepmerge some keys, which makes it more confusing.Your Environment 馃寧
The text was updated successfully, but these errors were encountered: