From e4244e3fcc7a1602a9bc4683c1831932eeae834c Mon Sep 17 00:00:00 2001 From: Don McKenzie Date: Thu, 9 Nov 2023 12:12:47 -0500 Subject: [PATCH] fix: remove unecessary dom re-calc in grid render --- packages/grid/src/Grid.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/grid/src/Grid.tsx b/packages/grid/src/Grid.tsx index ca23bd7ec6..0b9e2caa7f 100644 --- a/packages/grid/src/Grid.tsx +++ b/packages/grid/src/Grid.tsx @@ -806,7 +806,6 @@ class Grid extends PureComponent { if (!canvasContext) throw new Error('canvasContext not set'); if (!canvas.parentElement) throw new Error('Canvas has no parent element'); - const scale = Grid.getScale(canvasContext); // the parent wrapper has 100% width/height, and is used for determining size // we don't want to stretch the canvas to 100%, to avoid fractional pixels. // A wrapper element must be used for sizing, and canvas size must be @@ -814,6 +813,16 @@ class Grid extends PureComponent { const rect = canvas.parentElement.getBoundingClientRect(); const width = Math.floor(rect.width); const height = Math.floor(rect.height); + + // avoid triggering a dom re-calc if size hasn't changed + if ( + parseFloat(canvas.style.width) === width && + parseFloat(canvas.style.height) === height + ) { + return; + } + + const scale = Grid.getScale(canvasContext); canvas.style.width = `${width}px`; canvas.style.height = `${height}px`; canvas.width = width * scale;