Roll back renames on failed compound add operations

addFromBestiary and addFromPlayerCharacter rename existing combatants
before adding the new one. If the add fails, the renames were applied
without an undo entry. Restore the pre-operation snapshot on failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-26 23:31:11 +01:00
parent 17cc6ed72c
commit 29cdd19cab

View File

@@ -328,7 +328,10 @@ export function useEncounter() {
creatureId: cId,
});
if (isDomainError(result)) return null;
if (isDomainError(result)) {
store.save(snapshot);
return null;
}
const newState = pushUndo(undoRedoRef.current, snapshot);
undoRedoRef.current = newState;
@@ -363,7 +366,10 @@ export function useEncounter() {
playerCharacterId: pc.id,
});
if (isDomainError(result)) return;
if (isDomainError(result)) {
store.save(snapshot);
return;
}
const newState = pushUndo(undoRedoRef.current, snapshot);
undoRedoRef.current = newState;