Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unecessary dom re-calc in grid render #1632

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/grid/src/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -806,14 +806,23 @@ class Grid extends PureComponent<GridProps, GridState> {
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
// set manually to a floored value in css and a scaled value in width/height
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;
Expand Down
Loading