Skip to content

Build your personal knowledge base with Trilium Notes

fix(canvas): saving on start due to library change

Elian Doranc48bd9a5c357
diff --git a/apps/client/src/widgets/type_widgets/canvas/persistence.ts b/apps/client/src/widgets/type_widgets/canvas/persistence.ts
index 545a3d8564..4b31d826b6 100644
--- a/apps/client/src/widgets/type_widgets/canvas/persistence.ts
+++ b/apps/client/src/widgets/type_widgets/canvas/persistence.ts
@@ -176,10 +176,22 @@ export default function useCanvasPersistence(note: FNote, noteContext: NoteConte
currentSceneVersion.current = newSceneVersion;
}
},
- onLibraryChange: () => {
- libraryChanged.current = true;
- spacedUpdate.resetUpdateTimer();
- spacedUpdate.scheduleUpdate();
+ onLibraryChange: (libraryItems) => {
+ if (!apiRef.current || isReadOnly) return;
+
+ // Check if library actually changed by comparing with cached state
+ const hasChanges =
+ libraryItems.length !== libraryCache.current.length ||
+ libraryItems.some(item => {
+ const cachedItem = libraryCache.current.find(cached => cached.id === item.id);
+ return !cachedItem || cachedItem.name !== item.name;
+ });
+
+ if (hasChanges) {
+ libraryChanged.current = true;
+ spacedUpdate.resetUpdateTimer();
+ spacedUpdate.scheduleUpdate();
+ }
}
};
}