Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@typescript-eslint/parser": "^8.59.4",
"@vitejs/plugin-react": "^4.4.1",
"eslint": "^9.25.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"tailwindcss": "^4.1.0",
Expand Down
58 changes: 30 additions & 28 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@ export default function App() {
// (deep navigation from Play's settled match / recent matches).
const [careerFocusMatchId, setCareerFocusMatchId] = useState<number | null>(null);

// Declared before the effects that reference them (the compiler rules
// reject use-before-declaration inside effect bodies).
const fetchUserProfile = async () => {
try {
// authFetch transparently refreshes the access token on 401.
const resp = await authFetch(() => GetCurrentUser());
const userData = resp?.data ?? resp;
setUser(userData);
} catch (error) {
// Non-auth failures (e.g. the profile row is not provisioned until the
// first settled match) keep the session and render the empty profile.
console.error('Failed to fetch user profile:', error);
setUser(null);
}
};

const handleLogout = async () => {
try {
await LogoutAPI();
} catch (error) {
console.error('Logout API call failed:', error);
} finally {
localStorage.removeItem('access_token');
localStorage.removeItem('refresh_token');
setIsLoggedIn(false);
setUser(null);
setSelectedView('play');
}
};

useEffect(() => {
// Check if user is already logged in
const token = localStorage.getItem('access_token');
Expand All @@ -58,20 +88,6 @@ export default function App() {
return () => window.removeEventListener(SESSION_EXPIRED_EVENT, onSessionExpired);
}, []);

const fetchUserProfile = async () => {
try {
// authFetch transparently refreshes the access token on 401.
const resp = await authFetch(() => GetCurrentUser());
const userData = resp?.data ?? resp;
setUser(userData);
} catch (error) {
// Non-auth failures (e.g. the profile row is not provisioned until the
// first settled match) keep the session and render the empty profile.
console.error('Failed to fetch user profile:', error);
setUser(null);
}
};

const handleLoginSuccess = (tokenData: TokenData) => {
localStorage.setItem('access_token', tokenData.access_token);
localStorage.setItem('refresh_token', tokenData.refresh_token);
Expand All @@ -80,20 +96,6 @@ export default function App() {
setSelectedView('play');
};

const handleLogout = async () => {
try {
await LogoutAPI();
} catch (error) {
console.error('Logout API call failed:', error);
} finally {
localStorage.removeItem('access_token');
localStorage.removeItem('refresh_token');
setIsLoggedIn(false);
setUser(null);
setSelectedView('play');
}
};

const handleViewMatch = (id: number) => {
setCareerFocusMatchId(id);
setSelectedView('matches');
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/components/FriendList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export default function FriendList() {
const [error, setError] = useState<string | null>(null);
const [notImplemented, setNotImplemented] = useState(false);

useEffect(() => {
fetchFriends();
}, []);

// Declared before the effect that calls it (no use-before-declaration).
const fetchFriends = async () => {
setLoading(true);
setError(null);
Expand All @@ -56,6 +53,12 @@ export default function FriendList() {
}
};

useEffect(() => {
// Deferred so the loading flags aren't set synchronously on mount
// (react-hooks/set-state-in-effect).
queueMicrotask(fetchFriends);
}, []);

const getStatusLabel = (status: number) => {
switch (status) {
case 0: return msg.friends.statusPending;
Expand Down
34 changes: 21 additions & 13 deletions frontend/src/components/MyMatchesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,8 @@ export default function MyMatchesView({ userUid, focusMatchId, onConsumeFocus, o
}
}, [pageNum, pageSize]);

useEffect(() => {
fetchMatches();
}, [fetchMatches]);

// Deep navigation from Play: open the requested match detail once.
useEffect(() => {
if (focusMatchId != null) {
openDetail(focusMatchId, null);
onConsumeFocus?.();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [focusMatchId]);

// Declared before the focus effect that calls it (no
// use-before-declaration).
const openDetail = async (id: number, selfSummary: SelfSummaryView | null) => {
setDetail({ id } as MatchDetail);
setDetailSelfSummary(selfSummary);
Expand All @@ -166,6 +155,25 @@ export default function MyMatchesView({ userUid, focusMatchId, onConsumeFocus, o
}
};

useEffect(() => {
// Deferred so the loading flags aren't set synchronously
// (react-hooks/set-state-in-effect).
queueMicrotask(fetchMatches);
}, [fetchMatches]);

// Deep navigation from Play: open the requested match detail once.
useEffect(() => {
if (focusMatchId != null) {
// Deferred for the same reason as above (openDetail sets loading
// state synchronously).
queueMicrotask(() => {
openDetail(focusMatchId, null);
onConsumeFocus?.();
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [focusMatchId]);

const closeDetail = () => {
setDetail(null);
setDetailError(null);
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/PartyInvites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ export default function PartyInvites({ userUid, onChange }: PartyInvitesProps) {
}, []);

useEffect(() => {
loadInvites();
// Deferred so the loading flag isn't set synchronously on mount
// (react-hooks/set-state-in-effect); interval ticks are callbacks and
// already fine.
queueMicrotask(() => loadInvites());
pollRef.current = setInterval(() => loadInvites(true), POLL_MS);
return () => {
if (pollRef.current) clearInterval(pollRef.current);
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/components/PlayView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ export default function PlayView({ user, onViewMatch, onOpenRankings }: PlayView
const baselineGroupIds = useRef<Set<number>>(new Set());
const maxKnownMatchId = useRef(0);
const phaseRef = useRef<QueuePhase>('idle');
phaseRef.current = phase;

// Mirror the current phase for async readers (poll) — kept in an effect:
// writing refs during render is forbidden by the React Compiler rules.
useEffect(() => {
phaseRef.current = phase;
}, [phase]);

const refreshRecent = useCallback(async () => {
setRecentLoading(true);
Expand Down Expand Up @@ -291,7 +296,10 @@ export default function PlayView({ user, onViewMatch, onOpenRankings }: PlayView
if (phase !== 'queued' && phase !== 'found' && phase !== 'in_match') {
return;
}
poll();
// First tick deferred out of the render → effect synchronous path
// (set-state-in-effect): the interval callbacks below are already
// asynchronous subscriptions.
queueMicrotask(poll);
const pollHandle = setInterval(poll, POLL_MS);
const tickHandle = setInterval(() => setNow(Date.now()), 1000);
return () => {
Expand All @@ -303,7 +311,9 @@ export default function PlayView({ user, onViewMatch, onOpenRankings }: PlayView
// Restore an interrupted cycle (app restart while queued) and load the
// recent-matches list.
useEffect(() => {
refreshRecent();
// Deferred so the loading flag isn't set synchronously on mount
// (react-hooks/set-state-in-effect).
queueMicrotask(refreshRecent);
(async () => {
try {
const resp = await authFetch(() => GetMatchmakingStatus());
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/RankCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export default function RankCard({ rankType, season, winsCount, embedded = false
}, [rankType, season]);

useEffect(() => {
load();
// Deferred so the loading transition isn't set synchronously on mount
// (react-hooks/set-state-in-effect).
queueMicrotask(load);
}, [load]);

if (state === 'loading') {
Expand Down
18 changes: 11 additions & 7 deletions frontend/src/components/RankingView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useCallback } from 'react';
import { Trophy } from 'lucide-react';
import { Asset, EmptyState, ErrorState, Field, Icon, Panel, Select, Skeleton, Table, Td, Th } from '@ha/ui';
import { GetTopRankings } from '../../wailsjs/go/main/App';
Expand Down Expand Up @@ -30,11 +30,9 @@ export default function RankingView({ winsCount }: RankingViewProps) {
const [season, setSeason] = useState(1);
const [limit, setLimit] = useState(100);

useEffect(() => {
fetchRankings();
}, [rankType, season, limit]);

const fetchRankings = async () => {
// Declared before the effect that calls it; keyed on the query params so
// the effect re-fetches when they change.
const fetchRankings = useCallback(async () => {
setLoading(true);
setError(null);

Expand All @@ -56,7 +54,13 @@ export default function RankingView({ winsCount }: RankingViewProps) {
} finally {
setLoading(false);
}
};
}, [rankType, season, limit]);

useEffect(() => {
// Deferred so the loading flags aren't set synchronously
// (react-hooks/set-state-in-effect).
queueMicrotask(fetchRankings);
}, [fetchRankings]);

const getRankColor = (position: number) => {
switch (position) {
Expand Down
Loading