Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

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 [email protected] 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 [email protected].

@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 [email protected] restores the old behavior for React.PropTypes, fixing the [email protected] problem.

@bvaughn
Copy link
Contributor

bvaughn commented Apr 11, 2017

[email protected] ^

@gaearon
Copy link
Contributor

gaearon commented Apr 11, 2017

Thanks 😄 I keep typing that for some reason

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

Successfully merging a pull request may close this issue.

6 participants