From 29cdd19cabc1fa761617b766dcdc05a90cbc0fd8 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Mar 2026 23:31:11 +0100 Subject: [PATCH] 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) --- apps/web/src/hooks/use-encounter.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/web/src/hooks/use-encounter.ts b/apps/web/src/hooks/use-encounter.ts index c640cb1..5de527b 100644 --- a/apps/web/src/hooks/use-encounter.ts +++ b/apps/web/src/hooks/use-encounter.ts @@ -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;