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
This commit is contained in:
pj committed 2026-06-22 13:17:50 -04:00
1 parent 14eb3c4427
commit 258d5e5209
1 file changed
+7 -2
+7 -2
View File
@@ -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;