-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Bug: React hijacks console functions that may cause unpredictable behavior. #20367
Comments
This is intended behavior (introduced in #18547) that will be opt-out once #19710 lands in React devtools. Until then you can use a local workaround explained in #20090 (comment). |
But that is bad—It’s been tripping users up like what has been posted in comments on the original pull request:
At least, were the console suppression to be kept, it should be explicitly stated in the documentation. |
Yeah we should definitely add it to StrictMode documentation. Would you be interested in adding a note there?
Yes, we understand it would trip users. Both behaviors trip users in different ways. From our experience so far, it is still net positive to silence the noise from the second log, but it does come with the tradeoff of confusing other people in other situations once in a while. |
A pull request is opened in reactjs/react.dev#3426. |
The previous behavior has as well. Neither state is perfect which is why the devtools option is on the table.
Sounds great. Though we had the previous behavior documented as well and people were confused by it as well. This will just take some time until this knowledge proliferated enough through the community. |
To follow up on this, we've changed the logging behavior in 18 to be more intuitive. |
React version: 17.0.0
Steps To Reproduce
origLog()
function is called in every call toApp()
, the “hijacked” calls toconsole.log()
would only call the original method every other time, and therefore only even numbers are logged by this function.Link to code example:
https://codesandbox.io/s/jolly-bush-4ql7z?file=/src/index.js
The current behavior
React automatically “hijacks” the console’s methods to prevent duplicated logs, which might cause unpredictable behaviors.
The expected behavior
The original console methods are called by default even if in the component code.
The text was updated successfully, but these errors were encountered: