Closed rsi-yhe closed 2 years ago
I'm not aware of anything that could cause this. It's hard to debug this in more depth without a repro though. Can you share a playground or similar where I can test this behaviour myself?
https://codesandbox.io/s/empty-sun-5loi1?file=/src/App.js
I put two logs inside App.js
and you can see console have 2 output from loglevel
I can reproduce this, in codesandbox but also locally by exporting that same demo.
Testing it manually with a debugger, in fact it's the console.log
that's wrong here - that App() method really is called twice.
It turns out that in React v17 a recent feature hides the output of console.log during a new second rendering pass. That hides the console.log output, but not loglevel's output, which holds a reference to console.log from beforehand.
More detail available in https://github.com/facebook/react/issues/21783. This was fixed (moving the logic to React itself into React devtools, and showing the output but greyed out) in https://github.com/facebook/react/pull/22030, but it sounds like that will only be included in React v18, not v17.
I'm going to close this - loglevel is working correctly, this is a React issue.
React 18 is out, and double logs are no longer suppressed by default. (But they're slightly dimmed if you have DevTools installed.)
See https://github.com/facebook/react/issues/21783#issuecomment-1083412766.
Great, thanks for the update @gaearon!
Hi, I try to use
loglevel
in React, and seeing it print duplicate lines. The project is freshly created withcreate-react-app
and I just added two lines ofloglevel.log
andconsole.log
in theApp.tsx
. As you can see in chrome console,console.log
printed one time andloglevel.log
printed twice. I'm not sure if this is expected or I'm doing it wrong. Couldn't find any similar topic by just googling.