Skip to content

Build your personal knowledge base with Trilium Notes

fix(canvas): error when trying to save due to uninitialized API

Elian Doran2be9d7165971
diff --git a/apps/client/src/widgets/type_widgets/canvas.ts b/apps/client/src/widgets/type_widgets/canvas.ts
index 343e2489cf..0876d1b556 100644
--- a/apps/client/src/widgets/type_widgets/canvas.ts
+++ b/apps/client/src/widgets/type_widgets/canvas.ts
@@ -357,6 +357,9 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
if (options.is("databaseReadonly")) {
return;
}
+
+ if (!this.canvasInstance.isInitialized()) return;
+
// changeHandler is called upon any tiny change in excalidraw. button clicked, hover, etc.
// make sure only when a new element is added, we actually save something.
const isNewSceneVersion = this.canvasInstance.isNewSceneVersion();
diff --git a/apps/client/src/widgets/type_widgets/canvas_el.tsx b/apps/client/src/widgets/type_widgets/canvas_el.tsx
index a6f1ee16f6..b5018325d8 100644
--- a/apps/client/src/widgets/type_widgets/canvas_el.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas_el.tsx
@@ -76,6 +76,10 @@ export default class Canvas {
return this.currentSceneVersion === SCENE_VERSION_INITIAL;
}
+ isInitialized() {
+ return !!this.excalidrawApi;
+ }
+
resetScene(theme: Theme) {
this.excalidrawApi.updateScene({
elements: [],
@@ -194,4 +198,4 @@ function CanvasElement(opts: ExcalidrawProps) {
/>
</div>
);
-}
\ No newline at end of file
+}