Don't nag git updates so much

This commit is contained in:
Alex Gleason committed 2025-12-09 19:42:00 -06:00
1 parent 52863b808b
commit 83b20c88f0
1 file changed
+11 -3
+11 -3
View File
@@ -34,6 +34,7 @@ export function useGitFetch(projectId: string | null) {
const previousStateRef = useRef<{
defaultBranchOid: string | null;
currentBranchOid: string | null;
dataUpdatedAt: number;
} | null>(null);
const query = useQuery({
@@ -300,16 +301,17 @@ export function useGitFetch(projectId: string | null) {
// Show toast notifications when changes are detected
useEffect(() => {
if (!query.data || !query.isSuccess) {
if (!query.data || !query.isSuccess || query.dataUpdatedAt === undefined) {
return;
}
const currentState = {
defaultBranchOid: query.data.defaultBranchOid,
currentBranchOid: query.data.currentBranchOid,
dataUpdatedAt: query.dataUpdatedAt,
};
// Skip on first load
// Initialize on first load or after component remount
if (previousStateRef.current === null) {
previousStateRef.current = currentState;
return;
@@ -317,6 +319,12 @@ export function useGitFetch(projectId: string | null) {
const prevState = previousStateRef.current;
// Skip if this is the same data we've already seen (same dataUpdatedAt timestamp)
// This prevents showing toasts when navigating back to a project with cached data
if (prevState.dataUpdatedAt === currentState.dataUpdatedAt) {
return;
}
// Detect default branch changes
const defaultBranchChanged =
prevState.defaultBranchOid !== null &&
@@ -356,7 +364,7 @@ export function useGitFetch(projectId: string | null) {
// Update previous state
previousStateRef.current = currentState;
}, [query.data, query.isSuccess, toast, queryClient, projectId]);
}, [query.data, query.isSuccess, query.dataUpdatedAt, toast, queryClient, projectId]);
return query;
}