How should I prevent duplicate animation loops and input listeners when restarting a small HTML canvas brick-breaker game? Give a minimal lifecycle pattern, list the game state that must reset, and provide four checks that expose restart bugs. Do not produce a complete game or claim the pattern has been run.
Stop existing loop: Store the active frame handle (let rafId = null). When restarting, call cancelAnimationFrame(rafId) before allocating state or requesting a new frame. Reset & Start: Reassign state variables synchronously, then invoke rafId = requestAnimationFrame(loop).


