fix: use Phaser shutdown event for listener cleanup

Phaser's game.destroy() calls shutdown() on scenes, not destroy().
The old destroy() override was never called, causing stale event
listeners to persist and throw errors in React StrictMode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-07 22:00:15 +07:00
co-authored by Claude Opus 4.6
parent 289131ff7d
commit ced62af6ea
+11 -1
View File
@@ -41,6 +41,15 @@ export class GameScene extends Phaser.Scene {
this.shuffleHandler = () => this.handleShuffle();
this.stateManager.on("hint", this.hintHandler);
this.stateManager.on("shuffle", this.shuffleHandler);
// Clean up listeners on scene shutdown (called by game.destroy)
this.events.on("shutdown", () => {
if (this.timerEvent) {
this.timerEvent.destroy();
}
this.stateManager.off("hint", this.hintHandler);
this.stateManager.off("shuffle", this.shuffleHandler);
});
}
private renderBoard(): void {
@@ -313,9 +322,10 @@ export class GameScene extends Phaser.Scene {
this.renderBoard();
}
destroy(): void {
shutdown(): void {
if (this.timerEvent) {
this.timerEvent.destroy();
this.timerEvent = null;
}
if (this.stateManager) {
this.stateManager.off("hint", this.hintHandler);