fix repo dropdown selection (#388)

This commit is contained in:
Dylan Boudro 2025-07-11 08:53:55 -07:00 • committed by GitHub
parent 3f4576b24b
commit 0f5bb868d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -135,6 +135,9 @@ export function useGitHubApp(): UseGitHubAppReturn {
// Track if we've attempted to load from localStorage // Track if we've attempted to load from localStorage
const hasCheckedLocalStorageRef = useRef(false); const hasCheckedLocalStorageRef = useRef(false);
// Track previous installation ID to detect actual changes
const previousInstallationIdRef = useRef<string | null>(null);
const selectedRepository = useMemo(() => { const selectedRepository = useMemo(() => {
if (!selectedRepositoryParam) return null; if (!selectedRepositoryParam) return null;
try { try {
@ -294,21 +297,33 @@ export function useGitHubApp(): UseGitHubAppReturn {
// Refresh repositories when installation changes // Refresh repositories when installation changes
useEffect(() => { useEffect(() => {
if (currentInstallationId) { if (currentInstallationId) {
// Clear selected repository and branches when installation changes const previousInstallationId = previousInstallationIdRef.current;
setSelectedRepository(null);
setBranches([]);
setRepositoriesPage(1);
setRepositoriesHasMore(false);
// Reset auto-selection flags so they can run again for the new installation // Only clear repository if installation actually changed to a different value
hasAutoSelectedRef.current = false; if (
hasCheckedLocalStorageRef.current = false; previousInstallationId !== null &&
previousInstallationId !== currentInstallationId
) {
// Clear selected repository and branches when installation changes
setSelectedRepository(null);
setBranches([]);
setRepositoriesPage(1);
setRepositoriesHasMore(false);
// Fetch repositories for the new installation // Reset auto-selection flags so they can run again for the new installation
hasAutoSelectedRef.current = false;
hasCheckedLocalStorageRef.current = false;
}
// Update the previous installation ID reference
previousInstallationIdRef.current = currentInstallationId;
// Fetch repositories for the current installation
checkInstallation(); checkInstallation();
} }
}, [currentInstallationId]); }, [currentInstallationId]);
// Check localStorage for previously selected repository
useEffect(() => { useEffect(() => {
if ( if (
!hasCheckedLocalStorageRef.current && !hasCheckedLocalStorageRef.current &&