Skip to content

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

Closed
KjellConnelly opened this issue Apr 11, 2017 · 11 comments
Closed

NODE_ENV == 'production' then View.propTypes = undefined #423

KjellConnelly opened this issue Apr 11, 2017 · 11 comments

Comments

@KjellConnelly
Copy link

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?

@necolas
Copy link
Owner

necolas commented Apr 11, 2017

That plugin needs to import ViewPropTypes from React Native

@necolas necolas closed this as completed Apr 11, 2017
@necolas
Copy link
Owner

necolas commented Apr 11, 2017

Proptypes aren't used in production so including them is a waste

@RangerMauve
Copy link

@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?

@KjellConnelly
Copy link
Author

KjellConnelly commented Apr 12, 2017

@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.

@RangerMauve
Copy link

Thanks for the suggestion, @KjellConnelly
I was trying to monkey-patch Text.propTypes at runtime, but was unable to because the library code would be loaded before my code (curse you, es6 imports!).

I'l see what I can do with modifying the library directly.

RangerMauve added a commit to RangerMauve/react-native-hyperlink that referenced this issue Apr 12, 2017
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.
@necolas
Copy link
Owner

necolas commented Apr 12, 2017

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 necolas reopened this Apr 12, 2017
@RangerMauve
Copy link

@necolas Where would I find the relevant code to modify?

@necolas
Copy link
Owner

necolas commented Apr 12, 2017

@RangerMauve
Copy link

@necolas That's what I thought, but you're using the wrap mode so that code shouldn't be executing.

obipawan pushed a commit to obipawan/react-native-hyperlink that referenced this issue Apr 14, 2017
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.
@galkahana
Copy link

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.

@necolas
Copy link
Owner

necolas commented Apr 26, 2017

Fix is in v0.0.89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants