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, entityCache,
profileCache, profileCache,
recentlyRemovedIds: recentlyRemovedRef.current, recentlyRemovedIds: recentlyRemovedRef.current,
interactingWithIds: interactingWith, interactingWithIds: interactingWith,
currentItems: items, currentItemsRef: itemsRef,
}); });
return { return {
items, items,

View File

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