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

This commit is contained in:
Elian Doran
2025-09-19 16:26:06 +03:00
parent 3f562332c7
commit 2be9d71659
2 changed files with 8 additions and 1 deletions

View File

@@ -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();

View File

@@ -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>
);
}
}