From 43bbb37f4adbcee41dec5a234fbcf879574956de Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Thu, 29 Aug 2024 12:29:58 +0200 Subject: [PATCH] Fix debug canvas refresh on resize --- excalidraw-app/App.tsx | 7 ++++++- excalidraw-app/components/DebugCanvas.tsx | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/excalidraw-app/App.tsx b/excalidraw-app/App.tsx index 0076eead1..9b7eadff8 100644 --- a/excalidraw-app/App.tsx +++ b/excalidraw-app/App.tsx @@ -649,7 +649,12 @@ const ExcalidrawWrapper = () => { // Render the debug scene if the debug canvas is available if (debugCanvasRef.current && excalidrawAPI) { - debugRenderer(debugCanvasRef.current, appState, window.devicePixelRatio); + debugRenderer( + debugCanvasRef.current, + appState, + window.devicePixelRatio, + () => forceRefresh((prev) => !prev), + ); } }; diff --git a/excalidraw-app/components/DebugCanvas.tsx b/excalidraw-app/components/DebugCanvas.tsx index 00376c48f..b89ebd26e 100644 --- a/excalidraw-app/components/DebugCanvas.tsx +++ b/excalidraw-app/components/DebugCanvas.tsx @@ -60,12 +60,17 @@ const _debugRenderer = ( canvas: HTMLCanvasElement, appState: AppState, scale: number, + refresh: () => void, ) => { const [normalizedWidth, normalizedHeight] = getNormalizedCanvasDimensions( canvas, scale, ); + if (appState.height !== canvas.height || appState.width !== canvas.width) { + refresh(); + } + const context = bootstrapCanvas({ canvas, scale, @@ -130,8 +135,13 @@ export const saveDebugState = (debug: { enabled: boolean }) => { }; export const debugRenderer = throttleRAF( - (canvas: HTMLCanvasElement, appState: AppState, scale: number) => { - _debugRenderer(canvas, appState, scale); + ( + canvas: HTMLCanvasElement, + appState: AppState, + scale: number, + refresh: () => void, + ) => { + _debugRenderer(canvas, appState, scale, refresh); }, { trailing: true }, );