@@ -970,6 +970,32 @@ export function attach(
970
970
// lets the Fiber get reparented/remounted and still observe the previous errors/warnings.
971
971
// Unless we explicitly clear the logs from a Fiber.
972
972
const fiberToComponentLogsMap : WeakMap < Fiber , ComponentLogs > = new WeakMap ( ) ;
973
+ // Tracks whether we've performed a commit since the last log. This is used to know
974
+ // whether we received any new logs between the commit and post commit phases. I.e.
975
+ // if any passive effects called console.warn / console.error.
976
+ let needsToFlushComponentLogs = false ;
977
+
978
+ function bruteForceFlushErrorsAndWarnings ( ) {
979
+ // Refresh error/warning count for all mounted unfiltered Fibers.
980
+ let hasChanges = false ;
981
+ // eslint-disable-next-line no-for-of-loops/no-for-of-loops
982
+ for ( const devtoolsInstance of idToDevToolsInstanceMap . values ( ) ) {
983
+ if ( devtoolsInstance . kind === FIBER_INSTANCE ) {
984
+ const fiber = devtoolsInstance . data ;
985
+ const componentLogsEntry = fiberToComponentLogsMap . get ( fiber ) ;
986
+ const changed = recordConsoleLogs ( devtoolsInstance , componentLogsEntry ) ;
987
+ if ( changed ) {
988
+ hasChanges = true ;
989
+ updateMostRecentlyInspectedElementIfNecessary ( devtoolsInstance . id ) ;
990
+ }
991
+ } else {
992
+ // Virtual Instances cannot log in passive effects and so never appear here.
993
+ }
994
+ }
995
+ if ( hasChanges ) {
996
+ flushPendingEvents ( ) ;
997
+ }
998
+ }
973
999
974
1000
function clearErrorsAndWarnings ( ) {
975
1001
// Note, this only clears logs for Fibers that have instances. If they're filtered
@@ -1101,10 +1127,12 @@ export function attach(
1101
1127
}
1102
1128
1103
1129
// The changes will be flushed later when we commit.
1104
- // TODO: If the log happened in a passive effect, then this happens after we've
1130
+
1131
+ // If the log happened in a passive effect, then this happens after we've
1105
1132
// already committed the new tree so the change won't show up until we rerender
1106
1133
// that component again. We need to visit a Component with passive effects in
1107
1134
// handlePostCommitFiberRoot again to ensure that we flush the changes after passive.
1135
+ needsToFlushComponentLogs = true ;
1108
1136
}
1109
1137
1110
1138
// Patching the console enables DevTools to do a few useful things:
@@ -1322,6 +1350,8 @@ export function attach(
1322
1350
} ) ;
1323
1351
1324
1352
flushPendingEvents ( ) ;
1353
+
1354
+ needsToFlushComponentLogs = false ;
1325
1355
}
1326
1356
1327
1357
function getEnvironmentNames ( ) : Array < string > {
@@ -3464,6 +3494,8 @@ export function attach(
3464
3494
mountFiberRecursively ( root . current , false ) ;
3465
3495
3466
3496
flushPendingEvents ( root ) ;
3497
+
3498
+ needsToFlushComponentLogs = false ;
3467
3499
currentRoot = ( null : any ) ;
3468
3500
} ) ;
3469
3501
}
@@ -3486,6 +3518,15 @@ export function attach(
3486
3518
passiveEffectDuration ;
3487
3519
}
3488
3520
}
3521
+
3522
+ if ( needsToFlushComponentLogs ) {
3523
+ // We received new logs after commit. I.e. in a passive effect. We need to
3524
+ // traverse the tree to find the affected ones. If we just moved the whole
3525
+ // tree traversal from handleCommitFiberRoot to handlePostCommitFiberRoot
3526
+ // this wouldn't be needed. For now we just brute force check all instances.
3527
+ // This is not that common of a case.
3528
+ bruteForceFlushErrorsAndWarnings ( ) ;
3529
+ }
3489
3530
}
3490
3531
3491
3532
function handleCommitFiberRoot (
@@ -3595,6 +3636,8 @@ export function attach(
3595
3636
// We're done here.
3596
3637
flushPendingEvents ( root ) ;
3597
3638
3639
+ needsToFlushComponentLogs = false ;
3640
+
3598
3641
if ( traceUpdatesEnabled ) {
3599
3642
hook . emit ( 'traceUpdates' , traceUpdatesForNodes ) ;
3600
3643
}
0 commit comments