mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
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:
1 parent
14eb3c4427
commit
258d5e5209
1 file changed
+7
-2
@@ -75,8 +75,13 @@ export function EditorView() {
|
|||||||
|
|
||||||
const saveNow = useCallback(() => {
|
const saveNow = useCallback(() => {
|
||||||
const current = useBook.getState().book;
|
const current = useBook.getState().book;
|
||||||
if (current) saveBook(current).then(markSaved).catch((e) => setNotice(`Save failed: ${e}`));
|
if (!current) return;
|
||||||
}, [markSaved]);
|
saveBook(current)
|
||||||
|
.then(() => {
|
||||||
|
if (useBook.getState().book === current) markSaved();
|
||||||
|
})
|
||||||
|
.catch((e) => setNotice(`Save failed: ${e}`));
|
||||||
|
}, [markSaved, setNotice]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!book || !dirty || !isDesktop) return;
|
if (!book || !dirty || !isDesktop) return;
|
||||||
|
|||||||
Reference in new issue
Block a user