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

[data grid] Adding border to grid main element causes infinite rerender #8737

Closed
cherniavskii opened this issue Apr 24, 2023 · 5 comments · Fixed by #8882
Closed

[data grid] Adding border to grid main element causes infinite rerender #8737

cherniavskii opened this issue Apr 24, 2023 · 5 comments · Fixed by #8882
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Rendering layout Related to the data grid Rendering engine regression A bug, but worse

Comments

@cherniavskii
Copy link
Member

Demo: https://codesandbox.io/s/data-grid-community-forked-3ctumy

  • flex container
  • border on the .MuiDataGrid-main
  • container height so big that the table doesn't have a vertical scroll

(this one can be fixed by moving the border from main container element to root)

Originally posted by @Deraen in #8447 (comment)

@cherniavskii cherniavskii added component: data grid This is the name of the generic UI component, not the React module! feature: Rendering layout Related to the data grid Rendering engine labels Apr 24, 2023
@cherniavskii
Copy link
Member Author

@cherniavskii cherniavskii added the regression A bug, but worse label Apr 24, 2023
@cherniavskii
Copy link
Member Author

#8577 fixes it, but with a side-effect of horizontal scroll bar:
https://codesandbox.io/s/data-grid-community-forked-b8d17d

@cherniavskii
Copy link
Member Author

The issue seems to come from the fact that we use offsetWidth (which includes a border), but do not subtract border width from it:

const width = mainEl.offsetWidth || 0;
const win = ownerWindow(mainEl);
const computedStyle = win.getComputedStyle(mainEl);
const paddingLeft = parseInt(computedStyle.paddingLeft, 10) || 0;
const paddingRight = parseInt(computedStyle.paddingRight, 10) || 0;
const paddingTop = parseInt(computedStyle.paddingTop, 10) || 0;
const paddingBottom = parseInt(computedStyle.paddingBottom, 10) || 0;
const newHeight = height - paddingTop - paddingBottom;
const newWidth = width - paddingLeft - paddingRight;

We can use clientWidth instead, as it doesn't include border width.
Same applies to the height.

@lroos
Copy link

lroos commented May 4, 2023

I've run into a related issue with the upgrade to v6 (6.2.0) - the horizontal scrollbar appears while scrolling the list. I forked a demo sandbox here to illustrate.
https://codesandbox.io/s/sparkling-waterfall-3sdhkk?file=/demo.tsx
Only seems to happen when

  • border on .MuiDataGrid-main
  • at least 1 column is has flex: 1

Also if you set the Box to display: 'flex' then the whole grid slowly grows horizontally, as shown in #8447 which is trippy.

@Luv-m
Copy link

Luv-m commented Jun 16, 2023

Hello :),

Also if you set the Box to display: 'flex' then the whole grid slowly grows horizontally, as shown in #8447 which is trippy.

I still see this issue in 6.8.0. Is your fix going to go in the next release @cherniavskii ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Rendering layout Related to the data grid Rendering engine regression A bug, but worse
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants