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.
This commit is contained in:
2026-03-23 13:59:28 -07:00
committed by Naomi Carrigan
parent 06c80e186a
commit 4c3b9acfc5
+20 -1
View File
@@ -1281,7 +1281,26 @@ export const GameProvider = ({
if (availableBoss !== undefined) { if (availableBoss !== undefined) {
const { id: bossId, name: bossName } = availableBoss; const { id: bossId, name: bossName } = availableBoss;
isAutoBossingReference.current = true; 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) => { then((result) => {
setState((previous) => { setState((previous) => {
if (previous === null) { if (previous === null) {