fix: prevent infinite loop in git-diff screen
Added hasRequestedRef to track if a git diff request was already made for the current agentId. This prevents duplicate requests when the requestGitDiff function reference changes due to store updates. The issue was that requestGitDiff in the useEffect dependency array caused an infinite loop: request → store update → new function ref → effect re-runs → request again. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
6bae6f3a89
commit
5d5a196525
@@ -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<string | null>(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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user