Fix: Stabilize realtime subscription callbacks

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 20:02:35 +00:00
parent ee351de1fb
commit 44ab477abc
2 changed files with 9 additions and 10 deletions

View File

@@ -936,10 +936,10 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
},
entityCache,
profileCache,
recentlyRemovedIds: recentlyRemovedRef.current,
interactingWithIds: interactingWith,
currentItems: items,
});
recentlyRemovedIds: recentlyRemovedRef.current,
interactingWithIds: interactingWith,
currentItemsRef: itemsRef,
});
return {
items,

View File

@@ -61,8 +61,8 @@ export interface RealtimeSubscriptionConfig {
/** Set of IDs currently being interacted with */
interactingWithIds: Set<string>;
/** Current items in queue (for comparison) */
currentItems: ModerationItem[];
/** Current items in queue (for comparison) - using ref to avoid reconnections */
currentItemsRef: React.MutableRefObject<ModerationItem[]>;
}
/**
@@ -97,7 +97,7 @@ export function useRealtimeSubscriptions(
profileCache,
recentlyRemovedIds,
interactingWithIds,
currentItems,
currentItemsRef,
} = config;
// Debounce management for UPDATE events
@@ -339,7 +339,7 @@ export function useRealtimeSubscriptions(
const matchesEntity = matchesEntityFilter(updatedSubmission, filters.entityFilter);
const matchesStatus = matchesStatusFilter(updatedSubmission, filters.statusFilter);
const wasInQueue = currentItems.some(i => i.id === updatedSubmission.id);
const wasInQueue = currentItemsRef.current.some(i => i.id === updatedSubmission.id);
const shouldBeInQueue = matchesEntity && matchesStatus;
if (wasInQueue && !shouldBeInQueue) {
@@ -375,7 +375,7 @@ export function useRealtimeSubscriptions(
);
// Check if item actually changed
const currentItem = currentItems.find(i => i.id === fullItem.id);
const currentItem = currentItemsRef.current.find(i => i.id === fullItem.id);
if (currentItem && !hasItemChanged(currentItem, fullItem)) {
console.log('✅ Realtime UPDATE: No changes detected for', fullItem.id);
return;
@@ -392,7 +392,6 @@ export function useRealtimeSubscriptions(
pauseWhenHidden,
recentlyRemovedIds,
interactingWithIds,
currentItems,
debouncedUpdate,
fetchSubmissionDetails,
profileCache,