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

[Typography] Improve the upgrade story #13214

Merged
merged 3 commits into from
Oct 13, 2018

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Oct 11, 2018

I wanted to address the following pain points:

  • The warning spam in the console
  • The warnings threw in the examples
  • The warning globally disabled in the tests
  • The MuiThemeProvider requirement for correctly using the new typography variants
  • The process.env issue
  • The warning hard to find source location

I had to introduce a chainPropType helper along the way. Also, I have removed the option to globally disable the warnings.

Closes #13164
Closes #13163
Closes #13175

@oliviertassinari oliviertassinari added new feature New feature or request component: Typography The React component. labels Oct 11, 2018
@oliviertassinari oliviertassinari force-pushed the typography-upgrade-path branch 2 times, most recently from 270535b to 080be09 Compare October 11, 2018 23:38
@@ -16,13 +16,13 @@ module.exports = [
name: 'The initial cost paid for using one component',
webpack: true,
path: 'packages/material-ui/build/Paper/index.js',
limit: '18.2 KB',
limit: '17.6 KB',
Copy link
Member Author

Choose a reason for hiding this comment

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

🚀

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.

I pushed a solution for chainPropTypes that doesn't use private vars from prop-types and follows the documented pattern for calling propTypes directly.

@@ -1,4 +1,6 @@
const createDOM = require('./createDOM');

// eslint-disable-next-line no-underscore-dangle
global.__MUI_USE_NEW_TYPOGRAPHY_VARIANTS__ = true;
Copy link
Member

Choose a reason for hiding this comment

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

I had such a tunnel vision from all this "functional everywhere" that I totally forgot that global exists. Great call 👍

@@ -74,9 +74,11 @@ const theme = createMuiTheme({
});
```

or set `window.__MUI_USE_NEW_TYPOGRAPHY_VARIANTS__ = true;` if you don't use the theme.
Copy link
Member

Choose a reason for hiding this comment

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

-window.__MUI_USE_NEW_TYPOGRAPHY_VARIANTS__
+window.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__

for consistency.

Also we use global internally but window in the docs. window is not defined outside of browser, right? Maybe include global here before people ask.

Copy link
Member Author

@oliviertassinari oliviertassinari Oct 12, 2018

Choose a reason for hiding this comment

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

This option is targeting newcomers, they won't know what global is, hence window.

suppressDeprecationWarnings = process.env.MUI_SUPPRESS_DEPRECATION_WARNINGS,
useNextVariants = false,
// eslint-disable-next-line no-underscore-dangle
useNextVariants = false || global.__MUI_USE_NEW_TYPOGRAPHY_VARIANTS__,
Copy link
Member

Choose a reason for hiding this comment

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

This will always evaluate to just global.__MUI_USE_NEW_TYPOGRAPHY_VARIANTS__

@@ -27,27 +25,18 @@ export default function createTypography(palette, typography) {
// Tell Material-UI what's the font-size on the html element.
// 16px is the default font-size used by browsers.
htmlFontSize = 16,
suppressDeprecationWarnings = process.env.MUI_SUPPRESS_DEPRECATION_WARNINGS,
Copy link
Member

Choose a reason for hiding this comment

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

We could leave this in with global for users that want 3.2 without typography v2. I feel way to nostalgic about error_reporting(E_ALL ^ E_DEPRECATED), sorry.

Copy link
Member Author

Choose a reason for hiding this comment

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

We log a single warning now. I believe we don't need to hide it :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but each one of my unit test runs standalone - so now without this escape hatch my unit test output screen seems like something is definitely wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but each one of my unit test runs standalone

@jmcpeak Let's look into that. Are you using v3.2.2?

useNextVariants ||
!Object.keys(other).some(variant => typographyMigration.restyledVariants.includes(variant)),
'Material-UI: You are passing a variant to createTypography ' +
'that will be restyled in the next major release, without indicating that you ' +
Copy link
Member

Choose a reason for hiding this comment

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

That warning is now completely removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it was. It's not compatible with theme nesting.

@@ -29,7 +29,57 @@ import Typography from '@material-ui/core/Typography';
| <span class="prop-name">internalDeprecatedVariant</span> | <span class="prop-type">bool |   | A deprecated variant is used from an internal component. Users don't need a deprecation warning here if they switched to the v2 theme. They already get the mapping that will be applied in the next major release. |
| <span class="prop-name">noWrap</span> | <span class="prop-type">bool | <span class="prop-default">false</span> | If `true`, the text will not wrap, but instead will truncate with an ellipsis. |
| <span class="prop-name">paragraph</span> | <span class="prop-type">bool | <span class="prop-default">false</span> | If `true`, the text will have a bottom margin. |
| <span class="prop-name">variant</span> | <span class="prop-type">enum:&nbsp;'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'subtitle1', 'subtitle2', 'body1', 'body2', 'caption', 'button', 'overline', 'srOnly', 'inherit', "display4", 'display3', 'display2', 'display1', 'headline', 'title', 'subheading'<br> |   | Applies the theme typography styles. Use `body1` as the default value with the legacy implementation and `body2` with the new one. |
| <span class="prop-name">variant</span> | <span class="prop-type">chainPropType(
Copy link
Member

Choose a reason for hiding this comment

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

We need to update the API docs generator.

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 will finish that today. I did something like that 3 years ago, should be able to do it now.

@@ -0,0 +1,18 @@
function chainPropType(propType, check) {
Copy link
Member

Choose a reason for hiding this comment

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

I would vote for the reverse argument order since we're calling check first.

What do you think about using ...validators and then just iterating over them until we find the first error?

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 agree with reversing the order if it works with documentation generation.

let warning;

beforeEach(() => {
warning = mock(console).expects('error');
Copy link
Member Author

@oliviertassinari oliviertassinari Oct 12, 2018

Choose a reason for hiding this comment

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

I remember now why we didn't do it this way. we can no longer use console.log. Let's us our helper. It's really frustrating for debugging.

@oliviertassinari
Copy link
Member Author

@eps1lon Thank you for the review! I should be able to complete the effort this evening.

});

it('should not warn for supported types', () => {
PropTypes.checkPropTypes(
Copy link
Member Author

Choose a reason for hiding this comment

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

Our tests are no longer idempotent with this method. The warning only displays once.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed it. See facebook/react#4302. Solution inspired by facebook/react#7047 (comment)

@oliviertassinari oliviertassinari force-pushed the typography-upgrade-path branch 3 times, most recently from c14a10f to 0fd97e4 Compare October 13, 2018 09:43
@oliviertassinari oliviertassinari force-pushed the typography-upgrade-path branch 3 times, most recently from 838286b to d4995aa Compare October 13, 2018 10:47
@oliviertassinari oliviertassinari merged commit 118d339 into mui:master Oct 13, 2018
@oliviertassinari oliviertassinari deleted the typography-upgrade-path branch October 13, 2018 14:21
@oliviertassinari
Copy link
Member Author

It should be good. I hope we won't have to do another iteration. We will see. @eps1lon Thank you for the review, I have tried to leverage all your feedbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Typography The React component. new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants