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

[DataGrid] Round dimensions to avoid subpixel rendering error (@KenanYusuf) #15873

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ export const useGridVirtualScroller = () => {
}

const initialRect = node.getBoundingClientRect();
let lastSize = {
width: initialRect.width,
height: initialRect.height,
};

let lastSize = roundDimensions(initialRect);

apiRef.current.publishEvent('resize', lastSize);

Expand All @@ -162,10 +160,7 @@ export const useGridVirtualScroller = () => {
return;
}

const newSize = {
width: entry.contentRect.width,
height: entry.contentRect.height,
};
const newSize = roundDimensions(entry.contentRect);

if (newSize.width === lastSize.width && newSize.height === lastSize.height) {
return;
Expand Down Expand Up @@ -1109,3 +1104,12 @@ function bufferForDirection(
throw new Error('unreachable');
}
}

// Round to avoid issues with subpixel rendering
// https://github.com/mui/mui-x/issues/15721
function roundDimensions(dimensions: { width: number; height: number }) {
return {
width: Math.round(dimensions.width * 10) / 10,
height: Math.round(dimensions.height * 10) / 10,
};
}
20 changes: 20 additions & 0 deletions packages/x-data-grid/src/tests/layout.DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1318,4 +1318,24 @@ describe('<DataGrid /> - Layout & warnings', () => {
</div>,
);
});

// See https://github.com/mui/mui-x/issues/15721
it('should not exceed maximum call stack size caused by subpixel rendering', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// Need layouting
this.skip();
}

render(
<div style={{ width: 702.37 }}>
<DataGrid
columns={[
{ field: '1', flex: 1 },
{ field: '2', flex: 1 },
]}
rows={[]}
/>
</div>,
);
});
});
Loading