Fix stale ref in moderation queue

This commit is contained in:
gpt-engineer-app[bot]
2025-10-10 14:49:53 +00:00
parent 42f1794154
commit 0be9ef8b18

View File

@@ -503,6 +503,7 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
if (mergeResult.hasChanges) {
setItems(mergeResult.items);
itemsRef.current = mergeResult.items; // Update ref immediately to prevent stale comparisons
console.log('🔄 Queue updated (replace mode):', {
added: mergeResult.changes.added.length,
removed: mergeResult.changes.removed.length,
@@ -534,6 +535,7 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
if (mergeResult.hasChanges) {
setItems(mergeResult.items);
itemsRef.current = mergeResult.items; // Update ref immediately to prevent stale comparisons
console.log('🔄 Queue updated (manual refresh):', {
added: mergeResult.changes.added.length,
removed: mergeResult.changes.removed.length,
@@ -932,10 +934,14 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
}
console.log('🔄 Realtime UPDATE: Changes detected for', fullItem.id);
return prev.map(i => i.id === fullItem.id ? fullItem : i);
const newItems = prev.map(i => i.id === fullItem.id ? fullItem : i);
itemsRef.current = newItems; // Update ref immediately
return newItems;
} else {
console.log('🆕 Realtime UPDATE: Adding new item', fullItem.id);
return [fullItem, ...prev];
const newItems = [fullItem, ...prev];
itemsRef.current = newItems; // Update ref immediately
return newItems;
}
});
} catch (error) {