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

Bug: disableLogs mutates console #20575

Closed
jcdang opened this issue Jan 12, 2021 · 4 comments
Closed

Bug: disableLogs mutates console #20575

jcdang opened this issue Jan 12, 2021 · 4 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@jcdang
Copy link

jcdang commented Jan 12, 2021

It's noted on the docs pages at https://reactjs.org/docs/strict-mode.html

react-dom currently disables/mutates the global console in strict mode.

This seems to be an intentional feature/bug that's an unnecessary inconvenience.

React version: 17.0.1

Steps To Reproduce

  1. Use react-dom in strict mode
  2. Try to log something

The current behavior

logging is disabled in strict-mode

The expected behavior

Possible better solutions:

  • Make it more obvious that the console is being mutated/disabled
  • Use a proxy
@jcdang jcdang added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jan 12, 2021
@rickhanlonii
Copy link
Member

Hey @jcdang, thanks for submitting.

We only disable the console in the second call, you should still see logs from the first call.

Starting with React 17, React automatically modifies the console methods like console.log() to silence the logs in the second call to lifecycle functions.

If we didn't do this, the console would contain duplicate messages so we made the tradeoff to disable it in the second pass. This can have side effects, which we offer a workaround for.

@jcdang
Copy link
Author

jcdang commented Jan 12, 2021

Hey @rickhanlonii thanks for the explanation. You actually highlighted the underlying issue I am having! I'm trying to write a child reconciler right now and eventually discovered the existence of the two passes.

Would you be able to direct me to the design/intent for this two-pass approach or maybe how to disable it for child-reconcilers in the tree?

@rickhanlonii
Copy link
Member

Sure! Here's the PR adding the double render in strict mode, here's the issue that inspired it, and here's the PR for ignoring the second log.

@gaearon
Copy link
Collaborator

gaearon commented Mar 30, 2022

To follow up on this, we've changed the logging behavior in 18 to be more intuitive.
#21783 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants