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] Remove dependency on overridesResolver
for the variants
#27859
Conversation
@@ -283,7 +283,7 @@ describe('styled', () => { | |||
}); | |||
}); | |||
|
|||
it('variants should be skipped for non root slots', () => { | |||
it('variants should not be skipped for non root slots', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed wrong description on the test.
@@ -308,6 +308,30 @@ describe('styled', () => { | |||
}); | |||
}); | |||
|
|||
it('variants should not be skipped if overridesResolver is not defined', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "skipped" here. The test looks like it's not using variant
in any way and is also passing without the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you maybe use a theme that has styles for this specific variant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is used on line 322 https://github.com/mui-org/material-ui/pull/27859/files#diff-57eedb98ff493d66eb3e22d9e9ef1b1540504af969aa62accbb30b3a2a780044R322 The same theme is used in all tests. It is defined in https://github.com/mui-org/material-ui/blob/5585e100feec585f40f42ba2db605a56d1594718/packages/material-ui-system/src/styled.test.js#L140
Previously the variants
from the theme were not applied, if when creating the component, the overridesResolver
option was not applied. That's what I mean by should not be skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the variants from the theme were not applied, if when creating the component, the overridesResolver option was not applied.
But that's not related to the change in implementation in this PR. I ran the test with yarn test:karma
and in JSDOM locally on next
and it is passing.
This is confusing long-term because usually tests are coupled with the change in implementation. But here the change in implementation and test are unrelated.
Maybe you need to assert on different CSS properties to showcase what behavior changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point. I've fixed the tests. I was adding tests for a non root slot, but then variants are never applied :)
Did you mean const Button = styled("button", {
name: "MuiButton",
slot: "Root",
// overridesResolver: (props, styles) => styles.root,
- shouldForwardProp: (prop) => prop !== "color" && prop !== "contained"
+ shouldForwardProp: (prop) => prop !== "color" && prop !== "variant"
})({
display: "flex"
}); ? |
Good catch, yes I've updated the codesandbox. In the codesandbox if you uncomment line 23, you will see that the variants are applied. I think this is surprising that the two are related. |
This reverts commit e30e28e.
e30e28e: Just wanted to check what "restore file" does in the GitHub UI and it actually restores the file directly 😆 |
This is useful when you want to revert changes to some files on a PR from a phone :)) Where do you see this option? |
Might be from https://github.com/sindresorhus/refined-github |
It could be I can't see that option. Thanks for sharing! |
I noticed this issue when working on a test case for #27847
Here is a codesandbox that illustrates the issue - https://codesandbox.io/s/ancient-snow-45mhz?file=/src/App.js Note that the styles from the variants are being applied only if the
overridesResolver
is defined. These are not related and this dependency is not expected.