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

PropTypes throwing errors in production? #17

Closed
prettymuchbryce opened this issue Apr 11, 2017 · 10 comments · Fixed by #20
Closed

PropTypes throwing errors in production? #17

prettymuchbryce opened this issue Apr 11, 2017 · 10 comments · Fixed by #20
Labels

Comments

@prettymuchbryce
Copy link

prettymuchbryce commented Apr 11, 2017

Currently in React 15.5.0, PropTypes called manually can result in an Error being thrown in production. This is due to the productionTypeChecker now being used in 15.5.0. We suspect that the boolean argument passed to invariant was either intended to be flipped, or warning was intended to be used instead here. Passing false to invariant will always throw an error.

We're currently seeing this occur in production as a result of using react-router v1.0.3, which expects PropType validators to return errors, and doesn't account for any errors being thrown.

@franjohn21
Copy link

Codepen: http://codepen.io/franjohn21/pen/Wjeemd

@Daniel15
Copy link
Member

This seems to be an intentional design choice. From the readme in this repo:

In production, all validator functions are replaced with empty functions that throw an error. This is done to optimize the bundle size.

I suspect the reasoning is that proptype checks are usually only done in development. However, I wonder why it doesn't just become a no-op in production, rather than throwing 😕

@franjohn21
Copy link

If I'm reading the docs correctly, this functionality should throw an error in a future major release.

In a future major release of React, the code that implements PropType validation functions will be stripped in production. Once this happens, any code that calls these functions manually (that isn't stripped in production) will throw an error.

So throwing an error now is unintentional and breaks production builds particularly where 3rd party libraries manually called proptype functions.

@aweary
Copy link
Contributor

aweary commented Apr 11, 2017

Maybe @acdlite or @gaearon can shed some light on why prop-types is throwing in production before the next major React release.

@gaearon
Copy link
Contributor

gaearon commented Apr 11, 2017

This was an intentional breaking change inprop-types itself (as it is a completely new package) but I didn’t fully realize we switched React 15.5 to actually use the prop-types (and thus trigger the error).

We need to put out a fix for this asap, thanks for reporting.

@gaearon gaearon added the bug label Apr 11, 2017
flarnie added a commit to flarnie/react that referenced this issue Apr 11, 2017
To fix a breaking change which was not supposed to be included yet, we
reverted the change in prop-types v15.5.7 and are now pulling that into
React.

Related to fixing facebook/prop-types#17
@gaearon
Copy link
Contributor

gaearon commented Apr 11, 2017

This is fixed in prop-types@15.5.7 and we'll update React 15.x to enforce depending on it soon.
In the meantime you should be able to run rm -rf node_modules and npm install to fix this.

@gaearon
Copy link
Contributor

gaearon commented Apr 11, 2017

Fixed in react@15.5.4.

@gaearon
Copy link
Contributor

gaearon commented Apr 11, 2017

In case anyone is confused, the intended behavior is explained here:

https://github.com/reactjs/prop-types/blob/master/README.md#difference-from-reactproptypes-dont-call-validator-functions

I verified that react@15.5.4 restores the old behavior for React.PropTypes, fixing the react-router@1.x problem.

@bvaughn
Copy link
Contributor

bvaughn commented Apr 11, 2017

react@15.5.4 ^

@gaearon
Copy link
Contributor

gaearon commented Apr 11, 2017

Thanks 😄 I keep typing that for some reason

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

Successfully merging a pull request may close this issue.

6 participants