From 258d5e52091b20f02e913a3a68cc5fb8b5c67d18 Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 22 Jun 2026 13:17:50 -0400 Subject: [PATCH] fix(persist): guard markSaved against in-flight edits markSaved cleared dirty unconditionally, so an edit made while a save was in flight had its dirty flag wiped and its follow-up save dropped. Only clear dirty when the book reference is unchanged since the save started (immutable updates give a fresh reference per edit). Claude-Session: https://claude.ai/code/session_01RzTWrLiy4zGuw2hZSQGamk --- src/components/EditorView.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/EditorView.tsx b/src/components/EditorView.tsx index 0ce14c2..e98d81b 100644 --- a/src/components/EditorView.tsx +++ b/src/components/EditorView.tsx @@ -75,8 +75,13 @@ export function EditorView() { const saveNow = useCallback(() => { const current = useBook.getState().book; - if (current) saveBook(current).then(markSaved).catch((e) => setNotice(`Save failed: ${e}`)); - }, [markSaved]); + if (!current) return; + saveBook(current) + .then(() => { + if (useBook.getState().book === current) markSaved(); + }) + .catch((e) => setNotice(`Save failed: ${e}`)); + }, [markSaved, setNotice]); useEffect(() => { if (!book || !dirty || !isDesktop) return;