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

Deprecate calling PropTypes validators in production #7131

Closed
gaearon opened this issue Jun 27, 2016 · 2 comments
Closed

Deprecate calling PropTypes validators in production #7131

gaearon opened this issue Jun 27, 2016 · 2 comments

Comments

@gaearon
Copy link
Collaborator

gaearon commented Jun 27, 2016

We want to strip the code that implements PropTypes validation functions in production. This doesn’t mean React.PropTypes won’t exist—just that the functions will throw in production every time.

I did an initial attempt at this in #6401 but it’s too much of a change because people might be calling PropTypes in production right now for introspection, and we’d need to deprecate calling them in production before actually turning them into shims that throw errors.

@spicyj suggested a good first step: we should pass an extra argument to propType checkers. We would warn if that argument is not passed (or, if passed, does not match our “secret” value). This way we can detect if somebody manually calls PropTypes validators, and warn with console.error in production.

If you’d like to work on this, please comment here so we don’t have many people implementing this at the same time. You would need to:

  1. Pass an extra argument to prop type checkers.
  2. In production, warn inside the prop type checkers if they don’t receive the expected extra argument.
  3. The warning should say something like You are manually calling React.PropTypes validation functions in a production build. This is deprecated and will not work in the next major version.
  4. Don’t forget to write tests. You can peek at Dead code eliminate React.PropTypes checkers in production #6401 to see how to write tests that simulate production environment.
  5. Send a PR and we’ll discuss further!
@aweary
Copy link
Contributor

aweary commented Jun 27, 2016

I'd be happy to work on this!

@gaearon
Copy link
Collaborator Author

gaearon commented Jun 27, 2016

It’s yours! 💃

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

No branches or pull requests

2 participants