From c48bd9a5c35705ffbab992c6413dd84dcfcda882 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 23 Jan 2026 18:12:11 +0200 Subject: [PATCH] fix(canvas): saving on start due to library change --- .../type_widgets/canvas/persistence.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/canvas/persistence.ts b/apps/client/src/widgets/type_widgets/canvas/persistence.ts index 545a3d856..4b31d826b 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(); + } } }; }