generated from nhcarrigan/template
fix: prevent auto-save race from discarding collected exploration materials (#160)
Block the auto-save tick while the /explore/collect request is in-flight, clear the stale HMAC signature after the server-side DB write, and reset the save timer so the next auto-save fires after React has re-rendered with the new materials in stateReference — eliminating the window where a stale client snapshot could overwrite the server's freshly saved collect result.
This commit is contained in:
@@ -1810,7 +1810,18 @@ export const GameProvider = ({
|
||||
|
||||
const collectExploration = useCallback(
|
||||
async(areaId: string): Promise<ExploreCollectResponse> => {
|
||||
isSyncingReference.current = true;
|
||||
const result = await collectExplorationApi({ areaId });
|
||||
|
||||
/*
|
||||
* Collect mutates server state outside the normal save flow — clear the
|
||||
* stale HMAC signature and reset the timer so the next auto-save fires
|
||||
* after React has re-rendered with the new materials in stateReference.
|
||||
*/
|
||||
signatureReference.current = null;
|
||||
localStorage.removeItem("elysium_save_signature");
|
||||
lastSaveReference.current = Date.now();
|
||||
isSyncingReference.current = false;
|
||||
setState((previous) => {
|
||||
if (previous?.exploration === undefined) {
|
||||
return previous;
|
||||
|
||||
Reference in New Issue
Block a user