Fix random moderation queue reloads

This commit is contained in:
gpt-engineer-app[bot]
2025-10-10 19:58:00 +00:00
parent 351000c1ef
commit 99907a127a
2 changed files with 6 additions and 10 deletions

View File

@@ -950,7 +950,7 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
const newTimeout = setTimeout(() => {
updateFn();
realtimeUpdateDebounceRef.current.delete(submissionId);
}, 500); // Wait 500ms after last event
}, 1000); // Wait 1000ms after last event
realtimeUpdateDebounceRef.current.set(submissionId, newTimeout);
}, []);
@@ -1076,26 +1076,23 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
const hasChanged =
currentItem.status !== fullItem.status ||
currentItem.reviewed_at !== fullItem.reviewed_at ||
currentItem.reviewed_by !== fullItem.reviewed_by ||
currentItem.reviewer_notes !== fullItem.reviewer_notes ||
currentItem.assigned_to !== fullItem.assigned_to ||
currentItem.locked_until !== fullItem.locked_until ||
currentItem.escalated !== fullItem.escalated ||
JSON.stringify(currentItem.content) !== JSON.stringify(fullItem.content);
if (!hasChanged) {
console.log('✅ Realtime UPDATE: No changes detected for', fullItem.id);
return prev; // Keep existing array reference
return prev; // Keep existing array reference - PREVENTS RE-RENDER
}
console.log('🔄 Realtime UPDATE: Changes detected for', fullItem.id);
const newItems = prev.map(i => i.id === fullItem.id ? fullItem : i);
itemsRef.current = newItems; // Update ref immediately
return newItems;
// Shallow merge to preserve stable references
return prev.map(i => i.id === fullItem.id ? { ...i, ...fullItem } : i);
} else {
console.log('🆕 Realtime UPDATE: Adding new item', fullItem.id);
const newItems = [fullItem, ...prev];
itemsRef.current = newItems; // Update ref immediately
return newItems;
return [fullItem, ...prev];
}
});
} catch (error) {