mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 14:11:12 -05:00
Fix: Update stale ref in realtime handler
This commit is contained in:
@@ -502,8 +502,9 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
});
|
||||
|
||||
if (mergeResult.hasChanges) {
|
||||
// Update ref BEFORE setState to prevent race conditions
|
||||
itemsRef.current = mergeResult.items;
|
||||
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,
|
||||
@@ -526,6 +527,8 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
} else {
|
||||
// Manual refresh: Use smart comparison even for non-silent refreshes
|
||||
console.log('🔄 Manual refresh - checking for changes');
|
||||
console.log('📊 Before merge - itemsRef.current has', itemsRef.current.length, 'items');
|
||||
console.log('📊 New data from DB has', moderationItems.length, 'items');
|
||||
|
||||
const mergeResult = smartMergeArray(itemsRef.current, moderationItems, {
|
||||
compareFields: ['status', 'content', 'reviewed_at', 'reviewed_by', 'reviewer_notes', 'assigned_to', 'locked_until'],
|
||||
@@ -533,9 +536,18 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
addToTop: false,
|
||||
});
|
||||
|
||||
console.log('📊 Merge result:', {
|
||||
hasChanges: mergeResult.hasChanges,
|
||||
added: mergeResult.changes.added.length,
|
||||
removed: mergeResult.changes.removed.length,
|
||||
updated: mergeResult.changes.updated.length,
|
||||
finalCount: mergeResult.items.length,
|
||||
});
|
||||
|
||||
if (mergeResult.hasChanges) {
|
||||
// Update ref BEFORE setState to prevent race conditions
|
||||
itemsRef.current = mergeResult.items;
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user