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

View File

@@ -670,7 +670,6 @@ export const QueueItem = memo(({
// Deep comparison of content and other fields that affect rendering // Deep comparison of content and other fields that affect rendering
if (prevProps.item.reviewed_at !== nextProps.item.reviewed_at) return false; if (prevProps.item.reviewed_at !== nextProps.item.reviewed_at) return false;
if (prevProps.item.reviewed_by !== nextProps.item.reviewed_by) return false;
if (prevProps.item.reviewer_notes !== nextProps.item.reviewer_notes) return false; if (prevProps.item.reviewer_notes !== nextProps.item.reviewer_notes) return false;
if (prevProps.item.assigned_to !== nextProps.item.assigned_to) return false; if (prevProps.item.assigned_to !== nextProps.item.assigned_to) return false;
if (prevProps.item.locked_until !== nextProps.item.locked_until) return false; if (prevProps.item.locked_until !== nextProps.item.locked_until) return false;