From 88014ace4a9bf9c5c3189f4496695431e789faaf Mon Sep 17 00:00:00 2001 From: David Luzar <5153846+dwelle@users.noreply.github.com> Date: Fri, 9 Aug 2024 21:36:04 +0200 Subject: [PATCH] fix: drawing from 0-dimension canvas (#8356) --- packages/excalidraw/renderer/renderElement.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 (