fix(canvas): 解决画布节点撤销操作后图片丢失问题

- 添加 cleanupCanvasFiles 回调函数用于清理画布资源
- 将 cleanupAssetImages 替换为 cleanupCanvasFiles 以统一资源清理逻辑
- 在节点变更和画布清空时使用新的清理函数
- 修复撤销操作后节点信息恢复但本地图片数据被清理的错误
This commit is contained in:
HouYunFei
2026-05-26 15:50:36 +08:00
parent fda8efb362
commit 7e5179c54f
2 changed files with 12 additions and 4 deletions
@@ -292,6 +292,13 @@ function InfiniteCanvasPage() {
[activeChatId, backgroundMode, chatSessions, showImageInfo],
);
const cleanupCanvasFiles = useCallback(
(extra?: unknown) => {
cleanupAssetImages({ extra, history: historyRef.current, lastHistory: lastHistoryRef.current });
},
[cleanupAssetImages],
);
useEffect(() => {
if (!hydrated) return;
setProjectLoaded(false);
@@ -649,9 +656,9 @@ function InfiniteCanvasPage() {
setPreviewNodeId((current) => (current && allIds.has(current) ? null : current));
setRunningNodeId((current) => (current && allIds.has(current) ? null : current));
setContextMenu((current) => (current && allIds.has(current.nodeId) ? null : current));
cleanupAssetImages({ projectId, nodes: nodesRef.current.filter((node) => !allIds.has(node.id)), chatSessions });
cleanupCanvasFiles({ projectId, nodes: nodesRef.current.filter((node) => !allIds.has(node.id)), chatSessions });
},
[chatSessions, cleanupAssetImages, projectId],
[chatSessions, cleanupCanvasFiles, projectId],
);
const deselectCanvas = useCallback(() => {
@@ -676,8 +683,8 @@ function InfiniteCanvasPage() {
setRunningNodeId(null);
deselectCanvas();
setClearConfirmOpen(false);
cleanupAssetImages({ projectId, nodes: [], chatSessions: [] });
}, [cleanupAssetImages, deselectCanvas, projectId]);
cleanupCanvasFiles({ projectId, nodes: [], chatSessions: [] });
}, [cleanupCanvasFiles, deselectCanvas, projectId]);
const duplicateNode = useCallback((nodeId: string) => {
const source = nodesRef.current.find((node) => node.id === nodeId);