-
Notifications
You must be signed in to change notification settings - Fork 46k
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
Add DEV mode warning #8782
Add DEV mode warning #8782
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions. |
Tangential concern: Jest does output the warnings, which means Jest runs React in DEV mode. Are there precautions in place to also run the tests in prod mode? Otherwise we might risk relying too much on developer discipline not to introduce semantic changes during development. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Thanks for the PR @rauchg. I'm not sure I see the utility of adding an unconditional warning when using React in development. There's nothing inherently wrong with using React in dev mode. We already have a warning when using a minified copy of the development build. Is there another, specific situation you can think of where the current warning is insufficient and this new warning helps? I suspect this would likely just annoy users who are well aware they are using React in dev mode (as they are developing their application). |
I think what we need is a way to opt out of this once you've set up your environment. For example, should Create React App need this warning even though it has a verified environment set up? However, what if you use CRA's development mode to run benchmarks? |
@@ -28,6 +28,13 @@ var createFactory = ReactElement.createFactory; | |||
var cloneElement = ReactElement.cloneElement; | |||
|
|||
if (__DEV__) { | |||
console.log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use warning
to remain consistent with the rest of the codebase. I think there's other reasons we use warning
specifically, not sure offhand what they are. Since this is unconditional you would just do:
warning(false, "message")
But we'd likely want to dedupe this error message if accepted. See how the React.__spread
warning handles it below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aweary my understanding is that deduping is happening there because it's a function that can be called many times. Isn't this file meant to be evaluated once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rauchg ah, you're right. good catch, I missed that it was in a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another distinction is that warning
uses console.error()
, rather than console.log()
:
(cf. https://github.com/BerkeleyTrue/warning/blob/master/warning.js#L38)
However IMO console.warn()
would be the most appropriate in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also couldn't decide if it was exactly a warning. It's more along the lines of "Listening on http://localhost:3000", which everyone is ok with.
What if this was in a shared npm package instead of inside React that only did this, and we depend on it? So that any library that has this concern can depend on that package and then it will get deduped and only executed once. That way you won't see many such warnings in the future. |
In some benchmarks (like this one) React is many times slower when run in dev mode. Many people have incorrectly shipped a React dev version to production, and many others have run and published benchmarks against the dev version. This is an attempt to avoid hitting that same wall time and time again. |
I understand that it helps solve the problems of inaccurate benchmarks (been there), but this approach doesn't just target benchmarks or incorrectly shipped builds (which we try to handle already); it will target all cases where the development build is being used. The common case being developers just building their applications. It feels like the wrong approach to address corner cases at the expense of the common case. |
We decided not to do it for now. |
(But might revisit if DevTools don't help enough. In our experience they've made people much more aware of the issue, and we sell them on DevTools from the first time they use React.) |
Just a quick patch to get the discussion started.
The warning reads:
isomorphic
, so I made the decision based on thatwarning
utility because I don't need any conditions. Thoughts?console.log
should be checked for?https://fb.me/react-dev-mode
to a place where some notes are collected around: