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

Should the error message for directly calling validator functions be removed in production mode? #197

Open
markusenglund opened this issue Jul 15, 2018 · 2 comments

Comments

@markusenglund
Copy link

Currently, this package will throw an error when validator functions are called directly in both dev and production mode. Calling validator functions directly was previously supported when PropTypes was bundled with React in < react@15.4, so it's understandable that you want to warn developers who are changing to the prop-types package. However, it's been well over a year since directly calling validator functions was deprecated, so the utility of the error message is now considerably less.

My question is: Isn't it enough to warn developers only in dev mode?

By removing the error message from production mode, you could save around 160 bytes gzipped from the final production bundle. That's a paltry number, but since prop-types is bundled in basically every react app in existence it does add up.

@ljharb
Copy link
Collaborator

ljharb commented Apr 19, 2019

You can use checkPropTypes to avoid that error.

Either way, the amount of time that has passed, when any version can be installed at any time, isn’t really a factor.

@markusenglund
Copy link
Author

markusenglund commented Apr 20, 2019

What I tried to get across in my original comment was that by removing the error from prod mode we could save 160 bytes from basically every React site in existence which would be great. I guess I don’t get why throwing this error in production is any better than just returning undefined as is done when the package is used correctly. As I understand it, the message is only useful for a hypothetical project that

  • only uses production mode when developing,
  • decided to switch to the prop-types package, but did not realize that this behavior changed,
  • has code that relies on prop-types throwing in production when incorrect props are passed and
  • would not easily discover that said code didn’t work anymore.

Maybe I misunderstood something, but to me this error seems pretty useless. Removing it would technically be a breaking change though so not something you would want to do unless there is ever a 16.0 release.

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

2 participants