diff --git a/packages/app/src/app/git-diff.tsx b/packages/app/src/app/git-diff.tsx index dd1901252..fca720ca7 100644 --- a/packages/app/src/app/git-diff.tsx +++ b/packages/app/src/app/git-diff.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { View, Text, ScrollView, ActivityIndicator } from "react-native"; import { useLocalSearchParams } from "expo-router"; import { StyleSheet } from "react-native-unistyles"; @@ -97,6 +97,7 @@ function GitDiffContent({ serverLabel: string; }) { const [isLoading, setIsLoading] = useState(true); + const hasRequestedRef = useRef(null); const agent = useSessionStore((state) => agentId && serverId ? state.sessions[serverId]?.agents?.get(agentId) : undefined @@ -116,6 +117,12 @@ function GitDiffContent({ return; } + // Prevent duplicate requests for the same agentId + if (hasRequestedRef.current === agentId) { + return; + } + hasRequestedRef.current = agentId; + setIsLoading(true); requestGitDiff(agentId); diff --git a/plan.md b/plan.md index 4f82c5d7d..0ee2f3a8e 100644 --- a/plan.md +++ b/plan.md @@ -222,13 +222,14 @@ Remove `requestGitDiff` from useEffect dependencies in `git-diff.tsx`. Use a ref --- -- [ ] **Fix**: Remove requestGitDiff from useEffect dependencies in git-diff.tsx. +- [x] **Fix**: Remove requestGitDiff from useEffect dependencies in git-diff.tsx. - The `requestGitDiff` function reference changes on every store update - Remove it from the dependency array to prevent infinite loop - Use a ref to track if we've already requested the diff - Keep `agentId` as the only dependency (or use empty deps with agentId check) - Run typecheck after fix. + - **Done (2025-12-21 18:10)**: Added `hasRequestedRef` to track if a request was already made for the current agentId. The ref prevents duplicate requests when `requestGitDiff` reference changes due to store updates. Typecheck passes. - [ ] **Test**: Verify git diff loads correctly after fix.