Closed
Description
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
- Use react-dom in strict mode
- 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
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
rickhanlonii commentedon Jan 12, 2021
Hey @jcdang, thanks for submitting.
We only disable the console in the second call, you should still see logs from the first call.
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 commentedon 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 commentedon Jan 12, 2021
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 commentedon Mar 30, 2022
To follow up on this, we've changed the logging behavior in 18 to be more intuitive.
#21783 (comment)