fix(web): classic timer ran at 2x (idempotent startTimer) #96
Reference in New Issue
Block a user
Delete Branch "fix/classic-timer-double-count"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The
/play-classicgame timer counted at 2× speed, and it was the cause of the last 2 failingweb-e2etests (16/18 after #95).startTimer()always didtimerInterval = setInterval(...)without clearing any existing interval. Thevisibilitychangehandler callsstartTimer()on "visible", so a load-time visibilitychange (whilestartGame's timer is already running) stacks a second interval. From then onelapsedSecsincrements twice per second, andstopTimer()only clears one of the two — so the leak persists.This exactly reproduced the e2e numbers:
runFor(3000)→ expected0:03, got0:06(two intervals)runFor(2000)+hide+runFor(5000)+show+runFor(2000)→ expected0:04, got0:13(2×2 + 5_leaked + 2×2)Fix
Make
startTimer()idempotent — no-op if an interval is already running. One line, fixes both the user-visible 2× timer and the two timer tests.After merge
web-e2etriggers (touchessolitaire_server/web/) and should be 18/18. No wasm rebuild needed (game.js isn't a wasm-feeding crate).🤖 Generated with Claude Code