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

[core] Generate propTypes #2395

Merged
merged 14 commits into from
Sep 8, 2021
Merged

[core] Generate propTypes #2395

merged 14 commits into from
Sep 8, 2021

Conversation

m4theushw
Copy link
Member

One step towards #1826

I'm already working to generate the documentation for the components based on the propTypes.

@m4theushw m4theushw added the core Infrastructure work going on behind the scenes label Aug 20, 2021
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

It looks like we are on the right track. It feels like it uses a lot of the code of the main repository, which feels great.

docs/scripts/generateProptypes.ts Show resolved Hide resolved
}
return null;
}),
checkboxSelectionVisibleOnly: chainPropTypes(PropTypes.bool, (props: any) => {
Copy link
Member

Choose a reason for hiding this comment

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

We are losing the custom prop-types. If necessary, we can use this comment https://github.com/mui-org/material-ui/blob/a4e2ed82c76fffb5875ba96ab8c0efd5bcb424ef/packages/material-ui/src/Popper/Popper.js#L314

x the others

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment doesn't work in this situation. I'm already using it on other props. The prop-type for this prop was removed because checkboxSelectionVisibleOnly is omitted from the grid's props. The generator doesn't allow to have more prop-types than the props specified in the TS definition.

https://github.com/mui-org/material-ui-x/blob/1a0ad36f7380ba6bff04fa8f2b6366e001988734/packages/grid/data-grid/src/DataGridProps.ts#L11

Copy link
Member

Choose a reason for hiding this comment

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

What is the conclusion here ?
Do we have a way to improve the generator to keep those prop types ?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no way to include more props than those allowed in the interface of the component. In theory, if the prop is not in the interface it shouldn't be used in the component. We could add a warning in useDataGridProps if the user tries to use a prop from the Pro version.

Copy link
Member

Choose a reason for hiding this comment

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

Would you do this switch to useDataGridProps / useDataGridProProps in this PR ?
It would be sad to have a release without those warnings.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would you do this switch to useDataGridProps / useDataGridProProps in this PR ?

In another PR.

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Aug 21, 2021
package.json Outdated
@@ -61,6 +62,7 @@
"@material-ui/core": "^4.9.12",
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.54",
"@material-ui/utils": "^5.0.0-beta.4",
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 don't know why but without adding it here, the build fails. The dependency is already added to the DataGrid's package.json.

@m4theushw m4theushw changed the base branch from master to next August 27, 2021 15:28
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

  1. Saw a new warning opening http://0.0.0.0:3001/components/data-grid/columns/:

Screenshot 2021-09-04 at 16 18 28

  1. I expect the new prop-types to significantly increase the bundle size. But we didn't bring the bundle size checker from the main repo yet so we are blind. Also, we are no using the babel remove prop-type helpers to work around the limitation. What should do about it? Would it make more sense to only generate the prop-types for DataGrid and DataGridPro and hold on for the other components?

Comment on lines +50 to +51
// Fix const foo = /{{(.+?)}}/gs; crashing.
/prettier/,
Copy link
Member

Choose a reason for hiding this comment

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

It seems to work without, is it still needed?

Suggested change
// Fix const foo = /{{(.+?)}}/gs; crashing.
/prettier/,

Copy link
Member Author

Choose a reason for hiding this comment

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

Here it crashes if I remove.

image

Comment on lines -645 to -656
before(() => {
PropTypes.resetWarningCache();
});
Copy link
Member

Choose a reason for hiding this comment

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

Seeing this diff made me suspicious, so I gave it a try to confirm it: When running the tests in watch mode, the first run is green, but the second one is red. What motived the change of approach?

Copy link
Member Author

Choose a reason for hiding this comment

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

To test the warnings we were using PropTypes.checkPropTypes and feeding it with the prop-types. However, to get the prop-types they had to be attached to the exported component, which is a memo. Memoized components can't have prop-types so the generator attaches them to the DataGridRaw.

https://github.com/mui-org/material-ui-x/blob/2cd18f9cc5f4723a20f4ddec2ef3864e398e726b/packages/grid/data-grid/src/DataGrid.tsx#L38-L41

Since there's no more way to access the prop-types directly, I had to render the component to be able to test. The reason for seeing the second run red in watch mode: facebook/react#18251 (comment)

@m4theushw
Copy link
Member Author

I expect the new prop-types to significantly increase the bundle size.

@oliviertassinari It increased 5%. I'll open another PR to remove during the build the prop-types from internal components.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants