mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 08:31:13 -05:00
Fix stale ref in moderation queue
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user