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

[styles] Fix resolution of default props #24253

Merged
merged 4 commits into from Jan 9, 2021

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Jan 3, 2021

I have found this bug trying to customize the small and large variant of the button in #24095 for this spec:

Capture d’écran 2021-01-03 à 17 44 36

See this reproduction for the issue: https://codesandbox.io/s/globalthemevariants-material-demo-forked-rexjl?file=/demo.tsx

Capture d’écran 2021-01-03 à 18 15 22

import * as React from "react";
import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";

const theme = createMuiTheme({
  components: {
    MuiButton: {
      styleOverrides: {
        sizeSmall: {
          backgroundColor: "red"
        }
      }
    }
  }
});

export default function GlobalThemeVariants() {
  return (
    <ThemeProvider theme={theme}>
      <Button variant="contained" size="small">
        Small
      </Button>
    </ThemeProvider>
  );
}

Once we apply the patch of this pull request: https://codesandbox.io/s/globalthemevariants-material-demo-forked-13dfi?file=/package.json

Capture d’écran 2021-01-03 à 18 15 31

Regarding the tests, I'm not sure we need any, it seems to be simply about using the same approach as we use for writing the CSS but for the overrides.

Closes #24262

@mui-pr-bot
Copy link

mui-pr-bot commented Jan 3, 2021

Details of bundle changes

Generated by 🚫 dangerJS against 03aca94

@oliviertassinari oliviertassinari marked this pull request as ready for review January 3, 2021 17:03
eps1lon
eps1lon previously requested changes Jan 3, 2021
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed with a test.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Jan 3, 2021

Would it work if we add the test case for only one component, as a meant to validate that the whole integration is working? We could rely on the fact that the other components should all implement the same template.

This was the approach used since v1 for withStyles, the Button component was serving this purpose (as far as I remember). The solution seems simple enough to make me think that adding a new entry into describe conformance won't be efficient (spending more time writing test cases than saving us time and trust with regressions).

@eps1lon
Copy link
Member

eps1lon commented Jan 3, 2021

Would it work if we add the test case for only one component, as a meant to validate that the whole integration is working?

A test should be added for the behavior that was broken.

@mnajdova
Copy link
Member

mnajdova commented Jan 3, 2021

Changes looks good. The only reason the styleProps were not used, was because they were introduced later. I’d say we should add entry in the conformance suite that test that default props work for the overrides (that way even if we change the implementation it would safe us from making bug like this in the future).

@eps1lon
Copy link
Member

eps1lon commented Jan 5, 2021

Badge is still untested.

Comment on lines +63 to +65
if (!testStateOverrides) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When should this not be tested?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ask me, I would say most of the time we don't need to test it. We don't even fully test it right now, we take an arbitrary case. I would personally prefer we use the Button or Slider as a stress test template. It should be enough.

Badge is still untested.

The badge doesn't have state on its root element.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved away from the API in #24095 with this patch https://gist.github.com/oliviertassinari/60614c8c37d4ba10adc2a3b1aba1277e. The fix is meant for backward compatibility with v4.

Copy link
Member

@eps1lon eps1lon Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Badge is still untested.

The badge doesn't have state on its root element.

Then why did we need to change the implementation?

If you ask me, I would say most of the time we don't need to test it.

It already broke once.

The fix is meant for backward compatibility with v4.

describeConformanceV5 is not meant for v4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already broke once.

Exactly why I suggest the current tradeoff. If it breaks a second time, it will be a signal that it isn't enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument I have tried to defend is that it doesn't matter.

It does matter. Every implementation needs a test unless it isn't testable at which point one needs to make an argument why it isn't testable.

We don't decide by who writes the code if it needs to be tested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every implementation needs a test unless it isn't testable

I respectfully disagree. I think that we should also add "unless it's not worth it".

I think that it's like the 100% code coverage I have tried to push in the past and we gave up on. It's not always worth the time, once the opportunity cost is high, best to defer and be lazy.

Copy link
Member

@eps1lon eps1lon Jan 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I respectfully disagree. I think that we should also add "unless it's not worth it".

Impossible to collaborate on that premise since this argument applies anytime. Also: please stop cutting the quote. This is not what I said.

I think that it's like the 100% code coverage I have tried to push in the past and we gave up on.

At some point there comes a time where you should educate yourself more on the topic. I can only bring nudge you so far but if you believe that line coverage has anything to do with behavior testing I don't think you put any thought into verifying your work.

It becomes evident to me that you don't know at all why you made this change. I'm asking you a third time now: Why was the Badge changed but no test added? If you don't know what the code does then please revert it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impossible to collaborate on that premise since this argument applies anytime.

I think that we can default to testing less when we have a doubt. We have done this many times e.g. bugs in IE11, not worth it, it has been more efficient to have regressions and handle them. I think that it's best to wait for the pain to grow before doing something about it, we already have so many problems we know are important and need care.

Why was the Badge changed but no test added?

I have tried to answer it in #24253 (comment), the new generic test inside describeConformanceV5 doesn't support it. It's one rounding error compared to all the other components (144). Best to ignore it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry but you have the responsibility to explain the code you write. We have this expectation for any other contribution. What you did, expected behavior, actual behavior applies to everyone.

@oliviertassinari oliviertassinari merged commit df073cd into mui:next Jan 9, 2021
@oliviertassinari oliviertassinari deleted the fix-overridesResolver branch January 9, 2021 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[component: styleOverrides] No longer working
4 participants