fix(complement-race): show new passengers when route changes
Fixed bug where passengers wouldn't appear after completing a route. Problem: When a new route started, the Provider reset trainPosition to 0, but useTrackManagement was checking `trainPosition < 0` to detect resets. Since 0 is not < 0, the condition failed and passengers didn't update. Root cause: 1. Route completes, train at position ~107% 2. Client dispatches START_NEW_ROUTE with routeNumber=2 3. Server validates and broadcasts new state (route=2, new passengers) 4. Provider resets clientPosition to 0 5. useTrackManagement checks: - trainReset = trainPosition < 0 → FALSE (0 is not < 0!) - sameRoute = currentRoute === displayRouteRef.current → FALSE (2 !== 1) 6. Neither condition met, so displayPassengers doesn't update Solution: Changed trainReset condition from `trainPosition < 0` to `trainPosition <= 0` to treat position 0 as a reset. Also updated the pending track application logic with the same fix. Now passengers appear immediately when a new route starts. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -67,7 +67,7 @@ export function useTrackManagement({
|
||||
|
||||
// Apply pending track when train resets to beginning
|
||||
useEffect(() => {
|
||||
if (pendingTrackData && trainPosition < 0) {
|
||||
if (pendingTrackData && trainPosition <= 0) {
|
||||
setTrackData(pendingTrackData)
|
||||
previousRouteRef.current = currentRoute
|
||||
setPendingTrackData(null)
|
||||
@@ -77,9 +77,9 @@ export function useTrackManagement({
|
||||
// Manage passenger display during route transitions
|
||||
useEffect(() => {
|
||||
// Only switch to new passengers when:
|
||||
// 1. Train has reset to start position (< 0) - track has changed, OR
|
||||
// 1. Train has reset to start position (<= 0) - track has changed, OR
|
||||
// 2. Same route AND (in middle of track OR passengers have changed state)
|
||||
const trainReset = trainPosition < 0
|
||||
const trainReset = trainPosition <= 0
|
||||
const sameRoute = currentRoute === displayRouteRef.current
|
||||
const inMiddleOfTrack = trainPosition >= 10 && trainPosition < 90 // Avoid start/end transition zones
|
||||
|
||||
|
||||
Reference in New Issue
Block a user