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,7 +31,10 @@ export function useUnviewedValidations(currentProject: Project | null) {
const hoursSince = (Date.now() - new Date(v.validatedAt).getTime()) / (1000 * 60 * 60);
return hoursSince <= 24;
});
setCount(unviewed.length);
// Only update count if we're still on the same project (guard against race condition)
if (projectPathRef.current === projectPath) {
setCount(unviewed.length);
}
}
}
} catch (err) {