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] Warn when using a missing style rule #16501

Conversation

oliviertassinari
Copy link
Member

I'm exploring one possible approach to better handle #13875, #15454, #15573.
The idea here is to soften the PropTypes.oneOf prop type to PropTypes.string while keeping the warning for dynamic values with a classes proxy that detects accesses to none supported values.

However, I have found two drawbacks with this approach:

  1. The warning raised when it fails could be more specific.
  2. Logging classes return a rich object, it's less obvious that it's a simple object behind the proxy:
console.log(classes);

Capture d’écran 2019-07-06 à 11 40 56

@@ -178,7 +178,7 @@ function MarkdownDocs(props) {
</Portal>
)}

<AppContent disableToc={disableToc} className={classes.root}>
<AppContent disableToc={disableToc}>
Copy link
Member Author

Choose a reason for hiding this comment

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

A dead class name found with the new warning.

Copy link
Member

Choose a reason for hiding this comment

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

If you're concerned with using missing classes then using types is the better approach.

@oliviertassinari oliviertassinari requested a review from kof July 6, 2019 08:52
@@ -221,7 +222,7 @@ Typography.propTypes = {
/**
* Applies the theme typography styles.
*/
variant: PropTypes.oneOf([
variant: oneOfWithString([
Copy link
Member

Choose a reason for hiding this comment

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

How does react-docgen handle PropTypes.oneOfType([PropTypes.string, PropTypes.oneOf([...]])

@eps1lon
Copy link
Member

eps1lon commented Jul 6, 2019

Without React.warn we loose the component stack so for everyone on 16.8 this is a worse debugging experience.

For custom variants we have to defer checking to the style handler anyway. Not sure why we need a Proxy for that.

@oliviertassinari
Copy link
Member Author

Yeah, I'm not very happy with this approach. Another one I can think of. We could have a style method that internalize the warning logic:

diff --git a/packages/material-ui/src/Typography/Typography.js b/packages/material-ui/src/Typography/Typography.js
index 132001221..b75fe1486 100644
--- a/packages/material-ui/src/Typography/Typography.js
+++ b/packages/material-ui/src/Typography/Typography.js
@@ -146,9 +146,13 @@ const Typography = React.forwardRef(function Typography(props, ref) {
     <Component
       className={clsx(
         classes.root,
+        style({
+          classes,
+          key: `color${capitalize(color)}`,
+          enable: color !== 'initial',
+        }),
         {
           [classes[variant]]: variant !== 'inherit',
-          [classes[`color${capitalize(color)}`]]: color !== 'initial',
           [classes.noWrap]: noWrap,
           [classes.gutterBottom]: gutterBottom,
           [classes.paragraph]: paragraph,

@oliviertassinari
Copy link
Member Author

I will resume the effort later on.

@oliviertassinari oliviertassinari deleted the classes-warning-not-available branch February 8, 2020 20:44
@zannager zannager added the package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5. label Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants