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: useMemo exec twice in StrictMode,But console.log only exec once,console.debug exec twice #20982

Closed
cqh963852 opened this issue Mar 11, 2021 · 2 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@cqh963852
Copy link

React version:17.0.1

Steps To Reproduce

  1. Wrap app in StrictMode
  2. Do a function in useMemo

Link to code example:

https://codesandbox.io/s/vigilant-tree-igscd

The current behavior

The console.log in setSlot only exec once.
image

The expected behavior

Exec the console.log twice in setSlot funciton.

@cqh963852 cqh963852 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Mar 11, 2021
@bvaughn
Copy link
Contributor

bvaughn commented Mar 11, 2021

Related to #20367 and #20835 (this comment)

tl;dr Executing code twice in DEV is one of the things StrictMode does to detect side effects. React temporarily overrides console APIs like log before the second invocation to avoid double spamming the console.

This is a bit of a controversial decision but it seemed like the better of the two options.

@gaearon
Copy link
Collaborator

gaearon commented Mar 30, 2022

We've changed the logging behavior to be more intuitive in React 18.

See #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