[priority: 4] useGameLoop recreates interval every tick due to unstable tick reference #73
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Severity: 4 — High
File:
src/lib/game/stores/gameHooks.ts, lines 17-22Description:
The
tickfunction is recreated on every state change, causing theuseEffectto cleanup and re-run every 200ms. This is wasteful and can cause timing jitter.Fix: Use
getState()inside the interval callback:Starting work on Issue 73: useGameLoop recreates interval every tick due to unstable tick reference. Fixing to use getState() inside interval callback with empty dependency array.
Fixed: Changed
useGameLoopto useuseEffectwith empty dependency array[]anduseGameStore.getState().tick()inside the interval callback. This prevents interval recreation on every tick.