-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(Proptypes): remove from production build #684
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
Conversation
Here are the thoughts that come to mind:
Apologies as my thoughts are a little scattered. I haven't reached a clear resolve on this yet so I gave a brain dump for now. In summary, I think user's should remove propTypes themselves using the babel-plugin mentioned. I think we should consider moving |
Yes,
It sounds reasonable.
/**
* A loader is magic.
*
* @property as type.as As i magic
* @property active bool Marks loader active
* @property size array['small', 'medium', 'large', 'huge'] Defines loader size
*/
function Loader () {}
If we will keep props: {
as: true,
active: true,
inline: ['centered'],
size: SUI.SIZES,
} We can move there own constants for Component Explorer, but I think it's beyond good and evil, it will duplicate functionality of propTypes. props: {
as: META.PROPS.BOOL,
active: META.PROPS.BOOL,
inline: ['centered'],
size: SUI.SIZES,
} props: {
as: { type: META.PROPS.BOOL },
active: { type: META.PROPS.BOOL },
inline: {
type: META.PROPS.ARRAY,
values: ['centered'],
},
size: {
type: META.PROPS.ARRAY,
values: SUI.SIZES,
},
} |
I had a lengthy reply with code examples written out, however, after reviewing it I'm thinking this might not be worth the effort. In the end, we must have an array of I think I'd rather focus on publishing a babel plugin to transform import statements: import { Button, Card } from 'semantic-ui-react' Becomes: import Button from 'semantic-ui-react/Button'
import Card from 'semantic-ui-react/Card' This would require a PR to refactor how we publish so that the components are published as a flat directory. This avoids rewriting the imports to: import Button from 'semantic-ui-react/dist/commonjs/elements/Button' |
Agreed with that last comment. I don't think the benefits of removing |
Seems, I'm in the minority 😄 Anyway, I'm still thinking that storing array of handled props and removing Benefits aren't so great, but it's really beastly to see ( |
If we kept the focus on the props only and forgo my previous considerations (Component Explorer, doc blocks, etc.) then we could simply do this to remove propTypes in production: function Flag() {...}
if (process.env.NODE_ENV !== 'production' {
Flag.propTypes = {}
} The downside is that we'd then have to move all current This would also require common test updates. There are tests that assert that These are doable and not difficult, however, it means refactoring every component. We can and probably should do this at some point. I just don't personally have the bandwidth to embark on this at the moment. |
WIP
This PR is first part for #524.
What will we do there?
Props
First variant
Component._meta.props
will be renamed toComponent._meta.values
whileComponent._meta.props
will contain array of all handled props, (look to Loader.js in PR).Second variant
We will leave
Component._meta.props
as it as and add all left props to it:I think that first variant is sensible, any better suggestions there?
getUnhandledProps
This function will be more simple as you can see.
Tests
I've added test cases for
isConformant
that checks thatComponent._meta.props
and is equal to union ofautoControlledProps
,defaultProps
,propTypes
like it was ingetUnhandledProps
.Thoughts?
/cc @jcarbo @levithomason