-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Typography] Improve the upgrade story #13214
Conversation
270535b
to
080be09
Compare
@@ -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', |
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.
🚀
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 pushed a solution for chainPropTypes
that doesn't use private vars from prop-types
and follows the documented pattern for calling propTypes
directly.
test/utils/setup.js
Outdated
@@ -1,4 +1,6 @@ | |||
const createDOM = require('./createDOM'); | |||
|
|||
// eslint-disable-next-line no-underscore-dangle | |||
global.__MUI_USE_NEW_TYPOGRAPHY_VARIANTS__ = true; |
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 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. |
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.
-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.
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.
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__, |
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.
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, |
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.
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.
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.
We log a single warning now. I believe we don't need to hide it :)
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, 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.
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, 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 ' + |
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.
That warning is now completely removed.
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 was. It's not compatible with theme nesting.
pages/api/typography.md
Outdated
@@ -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: '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( |
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.
We need to update the API docs generator.
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 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) { |
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 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?
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 agree with reversing the order if it works with documentation generation.
let warning; | ||
|
||
beforeEach(() => { | ||
warning = mock(console).expects('error'); |
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 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.
@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( |
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.
Our tests are no longer idempotent with this method. The warning only displays once.
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 it. See facebook/react#4302. Solution inspired by facebook/react#7047 (comment)
c14a10f
to
0fd97e4
Compare
838286b
to
d4995aa
Compare
d4995aa
to
737a434
Compare
737a434
to
18c3925
Compare
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. |
I wanted to address the following pain points:
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