From 1a8093416e0feff774b6cdc6dfafdbafbb8baf7f Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Tue, 30 Sep 2025 15:09:53 -0500 Subject: [PATCH] fix: prevent route celebration from immediately reappearing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed race condition where route celebration modal would immediately reappear after clicking 'Continue Journey'. Root cause: trainPosition stayed >= 100 while showRouteCelebration was toggled, causing the interval check to re-trigger COMPLETE_ROUTE. Solution: 1. START_NEW_ROUTE now resets showRouteCelebration to false 2. Removed setTimeout delay and HIDE_ROUTE_CELEBRATION action 3. Single atomic state update prevents race condition Now continuing to next route works smoothly without modal flickering. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../components/GameDisplay.tsx | 23 ++++++++----------- .../context/ComplementRaceContext.tsx | 3 ++- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/apps/web/src/app/games/complement-race/components/GameDisplay.tsx b/apps/web/src/app/games/complement-race/components/GameDisplay.tsx index d51f871a..39adfea4 100644 --- a/apps/web/src/app/games/complement-race/components/GameDisplay.tsx +++ b/apps/web/src/app/games/complement-race/components/GameDisplay.tsx @@ -162,21 +162,16 @@ export function GameDisplay() { const handleContinueToNextRoute = () => { const nextRoute = state.currentRoute + 1 - // Hide celebration - dispatch({ type: 'HIDE_ROUTE_CELEBRATION' }) + // Start new route (this also hides celebration) + dispatch({ + type: 'START_NEW_ROUTE', + routeNumber: nextRoute, + stations: state.stations // Keep same stations for now + }) - // Generate new track and passengers for next route - setTimeout(() => { - dispatch({ - type: 'START_NEW_ROUTE', - routeNumber: nextRoute, - stations: state.stations // Keep same stations for now - }) - - // Generate new passengers - const newPassengers = generatePassengers(state.stations) - dispatch({ type: 'GENERATE_PASSENGERS', passengers: newPassengers }) - }, 100) + // Generate new passengers + const newPassengers = generatePassengers(state.stations) + dispatch({ type: 'GENERATE_PASSENGERS', passengers: newPassengers }) } if (!state.currentQuestion) return null diff --git a/apps/web/src/app/games/complement-race/context/ComplementRaceContext.tsx b/apps/web/src/app/games/complement-race/context/ComplementRaceContext.tsx index 679dda5f..c31a99f9 100644 --- a/apps/web/src/app/games/complement-race/context/ComplementRaceContext.tsx +++ b/apps/web/src/app/games/complement-race/context/ComplementRaceContext.tsx @@ -375,7 +375,8 @@ function gameReducer(state: GameState, action: GameAction): GameState { currentRoute: action.routeNumber, stations: action.stations, trainPosition: 0, - deliveredPassengers: 0 + deliveredPassengers: 0, + showRouteCelebration: false } case 'COMPLETE_ROUTE':