From 0ed93fb9b29664ca759567b97724ea3797bd7fd7 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 28 Feb 2025 09:44:51 +0100 Subject: [PATCH] Fix ToCToU issue with canvas resizing This could end up in endless resizing&repainting of the markup canvas. --- service.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/service.js b/service.js index 27c2144..863d8db 100644 --- a/service.js +++ b/service.js @@ -885,12 +885,14 @@ class BesService { this.canvasPanel.style.height = `${this.hostElement.scrollHeight}px` const dpr = window.devicePixelRatio const canvasPanelRect = this.canvasPanel.getBoundingClientRect() + const newCanvasWidth = Math.round(canvasPanelRect.width * dpr) + const newCanvasHeight = Math.round(canvasPanelRect.height * dpr) if ( - this.canvasPanel.width !== canvasPanelRect.width * dpr || - this.canvasPanel.height !== canvasPanelRect.height * dpr + this.canvasPanel.width !== newCanvasWidth || + this.canvasPanel.height !== newCanvasHeight ) { - this.canvasPanel.width = Math.round(canvasPanelRect.width * dpr) - this.canvasPanel.height = Math.round(canvasPanelRect.height * dpr) + this.canvasPanel.width = newCanvasWidth + this.canvasPanel.height = newCanvasHeight this.repositionAllMarkup() } if (this.isHostElementInline()) {