chore(canvas): set up cleanup

This commit is contained in:
Elian Doran 2025-06-11 14:11:53 +03:00
parent bb762cfab6
commit 892c27c945
No known key found for this signature in database

View File

@ -1,6 +1,6 @@
import "@excalidraw/excalidraw/index.css"; import "@excalidraw/excalidraw/index.css";
import { Excalidraw, getSceneVersion, exportToSvg } from "@excalidraw/excalidraw"; import { Excalidraw, getSceneVersion, exportToSvg } from "@excalidraw/excalidraw";
import { createElement, render } from "preact/compat"; import { createElement, render, unmountComponentAtNode } from "preact/compat";
import { AppState, BinaryFileData, ExcalidrawImperativeAPI, ExcalidrawProps, LibraryItem } from "@excalidraw/excalidraw/types"; import { AppState, BinaryFileData, ExcalidrawImperativeAPI, ExcalidrawProps, LibraryItem } from "@excalidraw/excalidraw/types";
import type { ComponentType } from "preact"; import type { ComponentType } from "preact";
import { ExcalidrawElement, NonDeletedExcalidrawElement, Theme } from "@excalidraw/excalidraw/element/types"; import { ExcalidrawElement, NonDeletedExcalidrawElement, Theme } from "@excalidraw/excalidraw/element/types";
@ -28,6 +28,7 @@ export default class Canvas {
} }
renderCanvas(targetEl: HTMLElement) { renderCanvas(targetEl: HTMLElement) {
unmountComponentAtNode(targetEl);
render(this.createCanvasElement({ render(this.createCanvasElement({
...this.opts, ...this.opts,
excalidrawAPI: (api: ExcalidrawImperativeAPI) => { excalidrawAPI: (api: ExcalidrawImperativeAPI) => {