@@ -361,20 +361,8 @@ export default function DocumentManager() {
361
361
// Check again if component is still mounted after the request completes
362
362
if ( ! isMountedRef . current ) return ;
363
363
364
- // Get new status counts (treat null as all zeros)
365
- const newStatusCounts = {
366
- processed : docs ?. statuses ?. processed ?. length || 0 ,
367
- processing : docs ?. statuses ?. processing ?. length || 0 ,
368
- pending : docs ?. statuses ?. pending ?. length || 0 ,
369
- failed : docs ?. statuses ?. failed ?. length || 0
370
- }
371
-
372
-
373
364
// Only update state if component is still mounted
374
365
if ( isMountedRef . current ) {
375
- // Update previous status counts
376
- prevStatusCounts . current = newStatusCounts
377
-
378
366
// Update docs state
379
367
if ( docs && docs . statuses ) {
380
368
const numDocuments = Object . values ( docs . statuses ) . reduce (
@@ -449,6 +437,32 @@ export default function DocumentManager() {
449
437
}
450
438
} , [ health , fetchDocuments , t , currentTab ] )
451
439
440
+ // Monitor docs changes to check status counts and trigger health check if needed
441
+ useEffect ( ( ) => {
442
+ if ( ! docs ) return ;
443
+
444
+ // Get new status counts
445
+ const newStatusCounts = {
446
+ processed : docs ?. statuses ?. processed ?. length || 0 ,
447
+ processing : docs ?. statuses ?. processing ?. length || 0 ,
448
+ pending : docs ?. statuses ?. pending ?. length || 0 ,
449
+ failed : docs ?. statuses ?. failed ?. length || 0
450
+ }
451
+
452
+ // Check if any status count has changed
453
+ const hasStatusCountChange = ( Object . keys ( newStatusCounts ) as Array < keyof typeof newStatusCounts > ) . some (
454
+ status => newStatusCounts [ status ] !== prevStatusCounts . current [ status ]
455
+ )
456
+
457
+ // Trigger health check if changes detected and component is still mounted
458
+ if ( hasStatusCountChange && isMountedRef . current ) {
459
+ useBackendState . getState ( ) . check ( )
460
+ }
461
+
462
+ // Update previous status counts
463
+ prevStatusCounts . current = newStatusCounts
464
+ } , [ docs ] ) ;
465
+
452
466
// Add dependency on sort state to re-render when sort changes
453
467
useEffect ( ( ) => {
454
468
// This effect ensures the component re-renders when sort state changes
0 commit comments