@@ -625,6 +625,142 @@ describe('console', () => {
625625 expect ( mockGroupCollapsed . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'groupCollapsed' ) ;
626626 } ) ;
627627
628+ it ( 'should double log from Effects if hideConsoleLogsInStrictMode is disabled in Strict mode' , ( ) => {
629+ global . __REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ = false ;
630+ global . __REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ = false ;
631+
632+ const container = document . createElement ( 'div' ) ;
633+ const root = ReactDOMClient . createRoot ( container ) ;
634+
635+ function App ( ) {
636+ React . useEffect ( ( ) => {
637+ fakeConsole . log ( 'log effect create' ) ;
638+ fakeConsole . warn ( 'warn effect create' ) ;
639+ fakeConsole . error ( 'error effect create' ) ;
640+ fakeConsole . info ( 'info effect create' ) ;
641+ fakeConsole . group ( 'group effect create' ) ;
642+ fakeConsole . groupCollapsed ( 'groupCollapsed effect create' ) ;
643+
644+ return ( ) => {
645+ fakeConsole . log ( 'log effect cleanup' ) ;
646+ fakeConsole . warn ( 'warn effect cleanup' ) ;
647+ fakeConsole . error ( 'error effect cleanup' ) ;
648+ fakeConsole . info ( 'info effect cleanup' ) ;
649+ fakeConsole . group ( 'group effect cleanup' ) ;
650+ fakeConsole . groupCollapsed ( 'groupCollapsed effect cleanup' ) ;
651+ } ;
652+ } ) ;
653+
654+ return < div /> ;
655+ }
656+
657+ act ( ( ) =>
658+ root . render (
659+ < React . StrictMode >
660+ < App />
661+ </ React . StrictMode > ,
662+ ) ,
663+ ) ;
664+ expect ( mockLog . mock . calls ) . toEqual ( [
665+ [ 'log effect create' ] ,
666+ [ 'log effect cleanup' ] ,
667+ [ 'log effect create' ] ,
668+ ] ) ;
669+ expect ( mockWarn . mock . calls ) . toEqual ( [
670+ [ 'warn effect create' ] ,
671+ [ 'warn effect cleanup' ] ,
672+ [ 'warn effect create' ] ,
673+ ] ) ;
674+ expect ( mockError . mock . calls ) . toEqual ( [
675+ [ 'error effect create' ] ,
676+ [ 'error effect cleanup' ] ,
677+ [ 'error effect create' ] ,
678+ ] ) ;
679+ expect ( mockInfo . mock . calls ) . toEqual ( [
680+ [ 'info effect create' ] ,
681+ [ 'info effect cleanup' ] ,
682+ [ 'info effect create' ] ,
683+ ] ) ;
684+ expect ( mockGroup . mock . calls ) . toEqual ( [
685+ [ 'group effect create' ] ,
686+ [ 'group effect cleanup' ] ,
687+ [ 'group effect create' ] ,
688+ ] ) ;
689+ expect ( mockGroupCollapsed . mock . calls ) . toEqual ( [
690+ [ 'groupCollapsed effect create' ] ,
691+ [ 'groupCollapsed effect cleanup' ] ,
692+ [ 'groupCollapsed effect create' ] ,
693+ ] ) ;
694+ } ) ;
695+
696+ it ( 'should not double log from Effects if hideConsoleLogsInStrictMode is enabled in Strict mode' , ( ) => {
697+ global . __REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ = false ;
698+ global . __REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ = true ;
699+
700+ const container = document . createElement ( 'div' ) ;
701+ const root = ReactDOMClient . createRoot ( container ) ;
702+
703+ function App ( ) {
704+ React . useEffect ( ( ) => {
705+ fakeConsole . log ( 'log effect create' ) ;
706+ fakeConsole . warn ( 'warn effect create' ) ;
707+ fakeConsole . error ( 'error effect create' ) ;
708+ fakeConsole . info ( 'info effect create' ) ;
709+ fakeConsole . group ( 'group effect create' ) ;
710+ fakeConsole . groupCollapsed ( 'groupCollapsed effect create' ) ;
711+
712+ return ( ) => {
713+ fakeConsole . log ( 'log effect cleanup' ) ;
714+ fakeConsole . warn ( 'warn effect cleanup' ) ;
715+ fakeConsole . error ( 'error effect cleanup' ) ;
716+ fakeConsole . info ( 'info effect cleanup' ) ;
717+ fakeConsole . group ( 'group effect cleanup' ) ;
718+ fakeConsole . groupCollapsed ( 'groupCollapsed effect cleanup' ) ;
719+ } ;
720+ } ) ;
721+
722+ return < div /> ;
723+ }
724+
725+ act ( ( ) =>
726+ root . render (
727+ < React . StrictMode >
728+ < App />
729+ </ React . StrictMode > ,
730+ ) ,
731+ ) ;
732+ expect ( mockLog . mock . calls ) . toEqual ( [
733+ [ 'log effect create' ] ,
734+ [ 'log effect cleanup' ] ,
735+ [ 'log effect create' ] ,
736+ ] ) ;
737+ expect ( mockWarn . mock . calls ) . toEqual ( [
738+ [ 'warn effect create' ] ,
739+ [ 'warn effect cleanup' ] ,
740+ [ 'warn effect create' ] ,
741+ ] ) ;
742+ expect ( mockError . mock . calls ) . toEqual ( [
743+ [ 'error effect create' ] ,
744+ [ 'error effect cleanup' ] ,
745+ [ 'error effect create' ] ,
746+ ] ) ;
747+ expect ( mockInfo . mock . calls ) . toEqual ( [
748+ [ 'info effect create' ] ,
749+ [ 'info effect cleanup' ] ,
750+ [ 'info effect create' ] ,
751+ ] ) ;
752+ expect ( mockGroup . mock . calls ) . toEqual ( [
753+ [ 'group effect create' ] ,
754+ [ 'group effect cleanup' ] ,
755+ [ 'group effect create' ] ,
756+ ] ) ;
757+ expect ( mockGroupCollapsed . mock . calls ) . toEqual ( [
758+ [ 'groupCollapsed effect create' ] ,
759+ [ 'groupCollapsed effect cleanup' ] ,
760+ [ 'groupCollapsed effect create' ] ,
761+ ] ) ;
762+ } ) ;
763+
628764 it ( 'should double log from useMemo if hideConsoleLogsInStrictMode is disabled in Strict mode' , ( ) => {
629765 global . __REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ = false ;
630766 global . __REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ = false ;
0 commit comments