Skip to content

Bug: disableLogs mutates console #20575

Closed
@jcdang

Description

@jcdang

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

Activity

rickhanlonii

rickhanlonii commented on Jan 12, 2021

@rickhanlonii
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

jcdang commented on Jan 12, 2021

@jcdang
Author

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

rickhanlonii commented on Jan 12, 2021

@rickhanlonii
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

gaearon commented on Mar 30, 2022

@gaearon
Collaborator

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jcdang@gaearon@rickhanlonii

        Issue actions

          Bug: disableLogs mutates console · Issue #20575 · facebook/react