mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 13:11:16 -05:00
Fix: Stabilize realtime subscription callbacks
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user