From 7a7d0bb5875e07e51141aa809dd6f152ecfa1178 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 5 Jun 2026 15:18:58 -0400 Subject: [PATCH] Clear undo history if applying an undo/redo entry fails A failed save means the object no longer matches the captured snapshot, so the remaining entries can't be trusted either. Clear both stacks instead of dropping just the failed entry. --- chrome/content/zotero/xpcom/undoHistory.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/undoHistory.js b/chrome/content/zotero/xpcom/undoHistory.js index 172a544210..66fcfadab4 100644 --- a/chrome/content/zotero/xpcom/undoHistory.js +++ b/chrome/content/zotero/xpcom/undoHistory.js @@ -168,7 +168,10 @@ Zotero.UndoHistory = { } catch (e) { Zotero.logError('UndoHistory: undo failed: ' + e); - // Entry is lost -- don't push to redo + // A failure means the object drifted out from under our snapshots, + // so the rest of the stack can't be trusted either. Discard history + // rather than risk applying stale values. + this.clear(); } return true; }, @@ -202,7 +205,10 @@ Zotero.UndoHistory = { } catch (e) { Zotero.logError('UndoHistory: redo failed: ' + e); - // Entry is lost -- don't push to undo + // A failure means the object drifted out from under our snapshots, + // so the rest of the stack can't be trusted either. Discard history + // rather than risk applying stale values. + this.clear(); } return true; },