fix: improve team selection logic and prevent duplicate fetches

- Enhanced GlobalTaskDetailDialog to handle loading states more effectively, preventing unnecessary re-fetching of team data.
- Updated selectTeam function in teamSlice to guard against duplicate in-flight fetches for the same team, improving performance and user experience.
- Refactored dependencies in useEffect to ensure proper data loading behavior.
This commit is contained in:
iliya 2026-02-28 22:25:04 +02:00
parent b346fd319d
commit 0f302521e4
2 changed files with 24 additions and 2 deletions

View file

@ -44,9 +44,25 @@ export const GlobalTaskDetailDialog = (): React.JSX.Element | null => {
// Load full team data in the background to enable "as before" details (logs/changes/members).
useEffect(() => {
if (!globalTaskDetail) return;
if (selectedTeamName === teamName && selectedTeamData) return;
if (!teamName) return;
// Avoid re-triggering selectTeam in a loop while the fetch is in flight.
// selectedTeamName is set immediately by selectTeam(), but selectedTeamData
// remains null until IPC resolves.
if (selectedTeamName === teamName) {
if (selectedTeamData || selectedTeamLoading) return;
// Retry once if we are on the right team but have no data and not loading (e.g. prior error).
}
void selectTeam(teamName, { skipProjectAutoSelect: true });
}, [globalTaskDetail, selectTeam, selectedTeamData, selectedTeamName, teamName]);
}, [
globalTaskDetail,
selectTeam,
selectedTeamData,
selectedTeamLoading,
selectedTeamName,
teamName,
]);
const isFullTeamLoaded = selectedTeamName === teamName && !!selectedTeamData;

View file

@ -354,6 +354,12 @@ export const createTeamSlice: StateCreator<AppState, [], [], TeamSlice> = (set,
},
selectTeam: async (teamName: string, opts) => {
// Guard: prevent duplicate in-flight fetches for the same team.
// GlobalTaskDetailDialog + tab navigation can call selectTeam() in quick succession.
if (get().selectedTeamLoading && get().selectedTeamName === teamName) {
return;
}
// Clear stale data immediately to prevent flash of previous team's content
const prev = get().selectedTeamName;
set({