diff --git a/packages/excalidraw/renderer/renderElement.ts b/packages/excalidraw/renderer/renderElement.ts index 4e6b11ac8..42473fcdc 100644 --- a/packages/excalidraw/renderer/renderElement.ts +++ b/packages/excalidraw/renderer/renderElement.ts @@ -199,7 +199,7 @@ const generateElementCanvas = ( zoom: Zoom, renderConfig: StaticCanvasRenderConfig, appState: StaticCanvasAppState, -): ExcalidrawElementWithCanvas => { +): ExcalidrawElementWithCanvas | null => { const canvas = document.createElement("canvas"); const context = canvas.getContext("2d")!; const padding = getCanvasPadding(element); @@ -210,6 +210,10 @@ const generateElementCanvas = ( zoom, ); + if (!width || !height) { + return null; + } + canvas.width = width; canvas.height = height; @@ -540,6 +544,10 @@ const generateElementWithCanvas = ( appState, ); + if (!elementWithCanvas) { + return null; + } + elementWithCanvasCache.set(element, elementWithCanvas); return elementWithCanvas; @@ -742,6 +750,10 @@ export const renderElement = ( renderConfig, appState, ); + if (!elementWithCanvas) { + return; + } + drawElementFromCanvas( elementWithCanvas, context, @@ -881,6 +893,10 @@ export const renderElement = ( appState, ); + if (!elementWithCanvas) { + return; + } + const currentImageSmoothingStatus = context.imageSmoothingEnabled; if (