-
Notifications
You must be signed in to change notification settings - Fork 1.8k
NODE_ENV == 'production' then View.propTypes = undefined #423
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
Comments
That plugin needs to import |
Proptypes aren't used in production so including them is a waste |
@necolas A dependency in my project, react-native-hyperlink is relying on Text.propTypes to be defined so that it can define it's own propTypes. Any suggestions on what to do to make this work for the production build? |
@RangerMauve The component I was working with also had Text.propTypes. Unfortunately there wasn't TextPropTypes to import, so as a workaround, I just made a pull request to this person's project and used ViewPropTypes in place of Text.propTypes and View.propTypes. For this component, it looks the same to me, so whatever style differences there may be, they weren't significant enough for me to care. You could do this, or possibly define your own TextPropTypes by copying the styles from the React Native GitHub page, though you would have to maintain that and any changes yourself. |
Thanks for the suggestion, @KjellConnelly I'l see what I can do with modifying the library directly. |
I'm using [react-native-web](https://github.com/necolas/react-native-web) in conjunction with this library in order to support more platforms with the same codebase. When building our app for development, everything works properly and this library does exactly what we need it to. However, react-native-web excludes propTypes when you do a production build in order to reduce bundle size and improve performance. This leads to [issues](necolas/react-native-web#423) when libraries depend on propTypes being defined. I propose feature-detecting whether Text.propTypes is actually defined so that people using react-native-web, or any bundlers for native that reduce size agressively, without affecting current users.
Oh I see. I think the fix is to patch the babel plugin so that it assigns an empty object to proptypes in production, rather than void. That will at least avoid errors if a module is trying to access a specific proptype |
@necolas Where would I find the relevant code to modify? |
@necolas That's what I thought, but you're using the |
I'm using [react-native-web](https://github.com/necolas/react-native-web) in conjunction with this library in order to support more platforms with the same codebase. When building our app for development, everything works properly and this library does exactly what we need it to. However, react-native-web excludes propTypes when you do a production build in order to reduce bundle size and improve performance. This leads to [issues](necolas/react-native-web#423) when libraries depend on propTypes being defined. I propose feature-detecting whether Text.propTypes is actually defined so that people using react-native-web, or any bundlers for native that reduce size agressively, without affecting current users.
There's a new version of babel-plugin-transform-react-remove-prop-types which updates wrap to replace with empty instead of replacing with null. |
Fix is in v0.0.89 |
One of the plugins I use uses View.propTypes to get style information. While it works with webpack-dev-server, webpack -p fails due to
View.propTypes = undefined
While looking through my bundle.js, I came across this line of code:
process.env.NODE_ENV !== "production" ? View.propTypes = _ViewPropTypes2.default : void 0;
Is there a reason this is here? Why would you want View.propTypes to be void in production, but not in development? If not, can we fix this?
The text was updated successfully, but these errors were encountered: