Fix unstable callbacks in moderation queue

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 05:00:23 +00:00
parent fcf5b9dba3
commit 540bd1cd7a
2 changed files with 17 additions and 8 deletions

View File

@@ -136,13 +136,13 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
},
});
// Use a stable callback via ref to prevent excessive re-renders
const lockStateChangeHandlerRef = useRef<() => void>();
const queue = useModerationQueue({
onLockStateChange: () => {
logger.log('🔄 Lock state changed, invalidating queue cache');
queueQuery.invalidate();
// Force immediate re-render by triggering a loading cycle
setLoadingState(prev => prev === "loading" ? "ready" : prev);
}
onLockStateChange: useCallback(() => {
lockStateChangeHandlerRef.current?.();
}, [])
});
const entityCache = useEntityCache();
const profileCache = useProfileCache();
@@ -177,6 +177,13 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
enabled: !!user,
});
// Update the lock state change handler ref whenever queueQuery changes
lockStateChangeHandlerRef.current = () => {
logger.log('🔄 Lock state changed, invalidating queue cache');
queueQuery.invalidate();
setLoadingState(prev => prev === "loading" ? "ready" : prev);
};
// Update items when query data changes
useEffect(() => {
if (queueQuery.items) {