Implement dynamic lobby polling with faster refresh rate and prevent concurrent requests

Added faster polling interval (700ms) for pre-game lobby to show joining players in near real-time, while keeping slower 2.5s refresh for active games. Implemented pending request flag to prevent concurrent API calls from overlapping. Added `cache: "no-store"` to fetch configuration to ensure fresh data on every request. Updated useEffect dependency array to re-initialize polling when game start state changes.
This commit is contained in:
2026-08-02 09:22:48 +02:00
parent 1bbbe31500
commit 29e063d88d
2 changed files with 11 additions and 5 deletions
+9 -4
View File
@@ -225,18 +225,23 @@ export default function App() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [gameId]);
// ✅ Live refresh (Members/Meta) damit neue Joiner ohne Reload sichtbar sind
// Für 56 Spieler reicht 2.5s völlig, ist "live genug" und schont Backend.
// ✅ Live refresh (Members/Meta) Lobby schnell, laufendes Spiel genügsamer.
useEffect(() => {
if (!me || !gameId) return;
let alive = true;
let pending = false;
const refreshInterval = gameMeta?.started ? 2500 : 700;
const tick = async () => {
if (pending) return;
pending = true;
try {
await loadGameMeta(); // refresh members + winner meta
} catch {
// ignore
} finally {
pending = false;
}
};
@@ -246,14 +251,14 @@ export default function App() {
const id = setInterval(() => {
if (!alive) return;
tick();
}, 2500);
}, refreshInterval);
return () => {
alive = false;
clearInterval(id);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [me?.id, gameId]);
}, [me?.id, gameId, gameMeta?.started]);
useEffect(() => {
// wid kann auch "" sein (kein Sieger)