From 4c3b9acfc54f48c6bfa08ba7af1cfd77aa2e1a94 Mon Sep 17 00:00:00 2001 From: Hikari Date: Mon, 23 Mar 2026 13:59:28 -0700 Subject: [PATCH] fix: sync game state before auto-boss challenge (#102) Auto-boss was calling the boss API directly without first flushing pending game state to the server. This inlines a saveGame call (using refs, matching the existing auto-save pattern) before the challenge so the server sees up-to-date state, consistent with the manual challenge flow. --- apps/web/src/context/gameContext.tsx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/web/src/context/gameContext.tsx b/apps/web/src/context/gameContext.tsx index 7cf6d47..0441ed0 100644 --- a/apps/web/src/context/gameContext.tsx +++ b/apps/web/src/context/gameContext.tsx @@ -1281,7 +1281,26 @@ export const GameProvider = ({ if (availableBoss !== undefined) { const { id: bossId, name: bossName } = availableBoss; isAutoBossingReference.current = true; - void challengeBossApi({ bossId }). + const syncBeforeBoss + = stateReference.current !== null && !isSyncingReference.current + ? saveGame({ + state: stateReference.current, + ...signatureReference.current === null + ? {} + : { signature: signatureReference.current }, + }).then((response) => { + if (response.signature !== undefined) { + signatureReference.current = response.signature; + localStorage.setItem( + "elysium_save_signature", + response.signature, + ); + } + }) + : Promise.resolve(); + void syncBeforeBoss.then(async() => { + return await challengeBossApi({ bossId }); + }). then((result) => { setState((previous) => { if (previous === null) {