Skip to content

Deprecate calling PropTypes validators in production #7131

@gaearon

Description

@gaearon

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions