fix: Prevent race condition in unviewed validations count update

- Added a guard to ensure the unviewed count is only updated if the current project matches the reference, preventing potential race conditions during state updates.
This commit is contained in:
Kacper
2025-12-23 23:28:02 +01:00
parent ef8eaa0463
commit 7b61a274e5

View File

@@ -31,9 +31,12 @@ export function useUnviewedValidations(currentProject: Project | null) {
const hoursSince = (Date.now() - new Date(v.validatedAt).getTime()) / (1000 * 60 * 60);
return hoursSince <= 24;
});
// Only update count if we're still on the same project (guard against race condition)
if (projectPathRef.current === projectPath) {
setCount(unviewed.length);
}
}
}
} catch (err) {
console.error('[useUnviewedValidations] Failed to load count:', err);
}