diff --git a/frontend/package-lock.json b/frontend/package-lock.json index b70a8a7..37afabe 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -25,7 +25,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", @@ -2681,16 +2681,23 @@ } }, "node_modules/eslint-plugin-react-hooks": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-5.2.0.tgz", - "integrity": "sha512-+f15FfK64YQwZdJNELETdn5ibXEUQmW1DZL6KXhNnc2heoy/sg9VJJeT7n8TlMWouzWqSWavFkIhHyIbIAEapg==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-7.1.1.tgz", + "integrity": "sha512-f2I7Gw6JbvCexzIInuSbZpfdQ44D7iqdWX01FKLvrPgqxoE7oMj8clOfto8U6vYiz4yd5oKu39rRSVOe1zRu0g==", "dev": true, "license": "MIT", + "dependencies": { + "@babel/core": "^7.24.4", + "@babel/parser": "^7.24.4", + "hermes-parser": "^0.25.1", + "zod": "^3.25.0 || ^4.0.0", + "zod-validation-error": "^3.5.0 || ^4.0.0" + }, "engines": { - "node": ">=10" + "node": ">=18" }, "peerDependencies": { - "eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0" + "eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 || ^10.0.0" } }, "node_modules/eslint-plugin-react-refresh": { @@ -3022,6 +3029,23 @@ "node": ">=8" } }, + "node_modules/hermes-estree": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.25.1.tgz", + "integrity": "sha512-0wUoCcLp+5Ev5pDW2OriHC2MJCbwLwuRx+gAqMTOkGKJJiBCLjtrvy4PWUGn6MIVefecRpzoOZ/UV6iGdOr+Cw==", + "dev": true, + "license": "MIT" + }, + "node_modules/hermes-parser": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.25.1.tgz", + "integrity": "sha512-6pEjquH3rqaI6cYAXYPcz9MS4rY6R4ngRgrgfDshRptUZIc3lw0MCIJIGDj9++mfySOuPTHB4nrSW99BCvOPIA==", + "dev": true, + "license": "MIT", + "dependencies": { + "hermes-estree": "0.25.1" + } + }, "node_modules/ignore": { "version": "7.0.9", "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.9.tgz", @@ -4147,6 +4171,29 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "4.6.7", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz", + "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zod-validation-error": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/zod-validation-error/-/zod-validation-error-4.0.2.tgz", + "integrity": "sha512-Q6/nZLe6jxuU80qb/4uJ4t5v2VEZ44lzQjPDhYJNztRQ4wyWc6VF3D3Kb/fAuPetZQnhS3hnajCf9CsWesghLQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "zod": "^3.25.0 || ^4.0.0" + } } } } diff --git a/frontend/package.json b/frontend/package.json index 92fd0d3..cfb9e10 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -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", diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index d842383..00b48ab 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -34,6 +34,36 @@ export default function App() { // (deep navigation from Play's settled match / recent matches). const [careerFocusMatchId, setCareerFocusMatchId] = useState(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'); @@ -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); @@ -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'); diff --git a/frontend/src/components/FriendList.tsx b/frontend/src/components/FriendList.tsx index 8c81ba7..a3a99d1 100644 --- a/frontend/src/components/FriendList.tsx +++ b/frontend/src/components/FriendList.tsx @@ -31,10 +31,7 @@ export default function FriendList() { const [error, setError] = useState(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); @@ -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; diff --git a/frontend/src/components/MyMatchesView.tsx b/frontend/src/components/MyMatchesView.tsx index ee9605f..9eba2fd 100644 --- a/frontend/src/components/MyMatchesView.tsx +++ b/frontend/src/components/MyMatchesView.tsx @@ -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); @@ -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); diff --git a/frontend/src/components/PartyInvites.tsx b/frontend/src/components/PartyInvites.tsx index 7dea7ff..0f8441d 100644 --- a/frontend/src/components/PartyInvites.tsx +++ b/frontend/src/components/PartyInvites.tsx @@ -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); diff --git a/frontend/src/components/PlayView.tsx b/frontend/src/components/PlayView.tsx index 64a495d..7794549 100644 --- a/frontend/src/components/PlayView.tsx +++ b/frontend/src/components/PlayView.tsx @@ -204,7 +204,12 @@ export default function PlayView({ user, onViewMatch, onOpenRankings }: PlayView const baselineGroupIds = useRef>(new Set()); const maxKnownMatchId = useRef(0); const phaseRef = useRef('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); @@ -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 () => { @@ -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()); diff --git a/frontend/src/components/RankCard.tsx b/frontend/src/components/RankCard.tsx index 8c0c260..4a9da23 100644 --- a/frontend/src/components/RankCard.tsx +++ b/frontend/src/components/RankCard.tsx @@ -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') { diff --git a/frontend/src/components/RankingView.tsx b/frontend/src/components/RankingView.tsx index b9e350a..4b599fd 100644 --- a/frontend/src/components/RankingView.tsx +++ b/frontend/src/components/RankingView.tsx @@ -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'; @@ -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); @@ -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) {