Keep image migration pending until save confirmation

This commit is contained in:
2026-11-06 22:21:03 +08:00
parent 570cd53fc3
commit 776b665727
8 changed files with 23 additions and 17 deletions
+11 -11
View File
@@ -276,19 +276,19 @@ export function useCanvasTree(root: string, workspace: string, initial: CanvasDo
}
async function migrateImages() {
return exclusive(async () => {
await flush();
const before = current.current.get(root)!;
const controller = new AbortController(); migrationAbort.current = controller;
let document: CanvasDocument;
try { document = await prepareManagedImages(before, api, workspace, controller.signal); }
finally { migrationAbort.current = null; }
if (!mounted.current || controller.signal.aborted) throw new DOMException("Aborted", "AbortError");
undo.current.push({ boardId: root, before }); redo.current = [];
publish(new Map(current.current).set(root, document));
const writer = writers.current.get(root)!;
await writer.enqueue(document); await writer.settled(); if (writer.error) throw new Error(writer.error);
try {
await flush();
const before = current.current.get(root)!;
const document = await prepareManagedImages(before, api, workspace, controller.signal);
if (!mounted.current || controller.signal.aborted) throw new DOMException("Aborted", "AbortError");
undo.current.push({ boardId: root, before }); redo.current = [];
publish(new Map(current.current).set(root, document));
const writer = writers.current.get(root)!;
await writer.enqueue(document); await writer.settled(); if (writer.error) throw new Error(writer.error);
} finally { migrationAbort.current = null; }
});
}
const retry = async () => { setError(""); setRetryLoad((v) => v + 1); for (const writer of writers.current.values()) await writer.retry(); };
return { documents, current, views, migrateImages, pendingCommand, retryPending: () => retryOperation.current ? exclusive(retryOperation.current) : Promise.resolve(null), prepareApply, recoveries, resolveRecovery, ensure, exportDocuments, dispatch, nodeAction, nodesChanged, edgesChanged, patchEdge, select, flush, command, refresh, read, busy: busy || pendingCommand, error, status, retry, undo: () => undoAction(), redo: () => undoAction(true), canUndo: !!undo.current.length, canRedo: !!redo.current.length, writers, rootDocument: documents.get(root)!, setError };
return { documents, current, views, migrateImages, migratingImages: !!migrationAbort.current, pendingCommand, retryPending: () => retryOperation.current ? exclusive(retryOperation.current) : Promise.resolve(null), prepareApply, recoveries, resolveRecovery, ensure, exportDocuments, dispatch, nodeAction, nodesChanged, edgesChanged, patchEdge, select, flush, command, refresh, read, busy: busy || pendingCommand, error, status, retry, undo: () => undoAction(), redo: () => undoAction(true), canUndo: !!undo.current.length, canRedo: !!redo.current.length, writers, rootDocument: documents.get(root)!, setError };
}