[data grid] Rows, grid headers, and cells re-render on RenderContext
change
#15618
Labels
bug 🐛
Something doesn't work
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
Steps to reproduce
Steps:
2.Turn on react update highlights in the devtools
3.Scroll enough to trigger RenderContext change (horizontally for GridHeaderCells and vertically for GridRows)
Current behavior
Too many re-renders, making memoization mostly an overhead with little gains.
Expected behavior
The problem stems from too many positional props being passed into these components, but in reality:
This should be calculated on GridRow level and passed as boolean props:
https://github.com/mui/mui-x/blob/721b285db4662de5c33e139c4b4cc4d63ae90019/packages/x-data-grid/src/components/cell/GridCell.tsx#L274C3-L281C5
Same here:
https://github.com/mui/mui-x/blob/721b285db4662de5c33e139c4b4cc4d63ae90019/packages/x-data-grid/src/components/columnHeaders/GridColumnHeaderItem.tsx#L138C3-L145C5
RenderContext should be removed and replaced with
firstColumnIndex
andlastColumnIndex
:mui-x/packages/x-data-grid/src/components/GridRow.tsx
Lines 33 to 46 in 721b285
Style object should be replaced with pinnedOffset, similar to how GridCells handle this:
mui-x/packages/x-data-grid/src/components/columnHeaders/GridColumnHeaderItem.tsx
Line 37 in 721b285
Should be easy enough fixes, but I don't have time myself to create a PR right now.
Maybe an eslint rule to prevent object props on these hot code paths would be helpful as well, because using non-stable objects like renderContext or style will just break fastMemo and potentially make it worse to memoize than not do it at all.
Context
No response
Your environment
npx @mui/envinfo
Search keywords: re-render
The text was updated successfully, but these errors were encountered: