fix(ui): ignore stale available-teams fetch on unmount or token change

This commit is contained in:
Yuneng Jiang 2026-07-20 20:35:51 -07:00
parent fe57eedb5c
commit 484cc12ab6
No known key found for this signature in database

View file

@ -16,6 +16,8 @@ const AvailableTeamsPanel: React.FC<AvailableTeamsProps> = ({ accessToken, userI
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
let ignore = false;
const fetchAvailableTeams = async () => {
if (!accessToken || !userID) {
setIsLoading(false);
@ -24,15 +26,23 @@ const AvailableTeamsPanel: React.FC<AvailableTeamsProps> = ({ accessToken, userI
try {
const response = await availableTeamListCall(accessToken);
setAvailableTeams(response);
if (!ignore) {
setAvailableTeams(response);
}
} catch (error) {
console.error("Error fetching available teams:", error);
} finally {
setIsLoading(false);
if (!ignore) {
setIsLoading(false);
}
}
};
fetchAvailableTeams();
return () => {
ignore = true;
};
}, [accessToken, userID]);
const handleJoinTeam = async (teamId: string) => {