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] Fix Maximum call stack size exceeded error when using fractional width #9516

Merged
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 @@ -109,7 +109,7 @@ export function useGridDimensions(

if (props.autoHeight) {
hasScrollY = false;
hasScrollX = Math.round(columnsTotalWidth) > rootDimensionsRef.current.width;
hasScrollX = columnsTotalWidth > rootDimensionsRef.current.width;

viewportOuterSize = {
width: rootDimensionsRef.current.width,
Expand All @@ -122,7 +122,7 @@ export function useGridDimensions(
};

const scrollInformation = hasScroll({
content: { width: Math.round(columnsTotalWidth), height: rowsMeta.currentPageTotalHeight },
content: { width: columnsTotalWidth, height: rowsMeta.currentPageTotalHeight },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #9236 we started to use fractional size. Rounding the columns total width breaks the equality comparison

container: {
width: viewportOuterSize.width,
height: viewportOuterSize.height - pinnedRowsHeight.top - pinnedRowsHeight.bottom,
Expand Down
15 changes: 15 additions & 0 deletions packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,7 @@ describe('<DataGrid /> - Layout & Warnings', () => {
expect(virtualScroller.clientWidth).to.equal(initialVirtualScrollerWidth);
});

// See https://github.com/mui/mui-x/issues/8689#issuecomment-1582616570
it('should not add scrollbars when the parent container has fractional size', async function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// Need layouting
Expand All @@ -1146,4 +1147,18 @@ describe('<DataGrid /> - Layout & Warnings', () => {
// It should not have a vertical scrollbar
expect(virtualScroller.scrollHeight - virtualScroller.clientHeight).to.equal(0);
});

// See https://github.com/mui/mui-x/issues/9510
it('should not exceed maximum call stack size when the parent container has fractional width', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// Need layouting
this.skip();
}

render(
<div style={{ height: '100%', width: 400.6 }}>
<DataGrid rows={[{ id: 1 }]} columns={[{ field: 'id', flex: 1 }]} />
</div>,
);
});
});