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 dimensions lag issue after autosize #13587

Merged
merged 2 commits into from
Jun 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function useGridDimensions(
const logger = useGridLogger(apiRef, 'useResizeContainer');
const errorShown = React.useRef(false);
const rootDimensionsRef = React.useRef(EMPTY_SIZE);
const dimensionsState = useGridSelector(apiRef, gridDimensionsSelector);
const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
const pinnedColumns = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
Expand Down Expand Up @@ -302,26 +303,25 @@ export function useGridDimensions(
}, [apiRef, savedSize, updateDimensions]);

const root = apiRef.current.rootElementRef.current;
const dimensions = apiRef.current.state.dimensions;
Copy link
Member

Choose a reason for hiding this comment

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

I'd be curious to know why the material-ui/no-direct-state-access linting rule did not catch it 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I was under the impression this rule is not activated, as there are multiple instances where we do direct state access around the code base. Should it detect all the instances? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I don't know, Matheus created it I think, since it's a rule that is mostly here for us, if it does not work maybe we can fix it or drop it 😆

useEnhancedEffect(() => {
if (!root) {
return;
}
const set = (k: string, v: string) => root.style.setProperty(k, v);
set('--DataGrid-width', `${dimensions.viewportOuterSize.width}px`);
set('--DataGrid-hasScrollX', `${Number(dimensions.hasScrollX)}`);
set('--DataGrid-hasScrollY', `${Number(dimensions.hasScrollY)}`);
set('--DataGrid-scrollbarSize', `${dimensions.scrollbarSize}px`);
set('--DataGrid-rowWidth', `${dimensions.rowWidth}px`);
set('--DataGrid-columnsTotalWidth', `${dimensions.columnsTotalWidth}px`);
set('--DataGrid-leftPinnedWidth', `${dimensions.leftPinnedWidth}px`);
set('--DataGrid-rightPinnedWidth', `${dimensions.rightPinnedWidth}px`);
set('--DataGrid-headerHeight', `${dimensions.headerHeight}px`);
set('--DataGrid-headersTotalHeight', `${dimensions.headersTotalHeight}px`);
set('--DataGrid-topContainerHeight', `${dimensions.topContainerHeight}px`);
set('--DataGrid-bottomContainerHeight', `${dimensions.bottomContainerHeight}px`);
set('--height', `${dimensions.rowHeight}px`);
}, [root, dimensions]);
set('--DataGrid-width', `${dimensionsState.viewportOuterSize.width}px`);
set('--DataGrid-hasScrollX', `${Number(dimensionsState.hasScrollX)}`);
set('--DataGrid-hasScrollY', `${Number(dimensionsState.hasScrollY)}`);
set('--DataGrid-scrollbarSize', `${dimensionsState.scrollbarSize}px`);
set('--DataGrid-rowWidth', `${dimensionsState.rowWidth}px`);
set('--DataGrid-columnsTotalWidth', `${dimensionsState.columnsTotalWidth}px`);
set('--DataGrid-leftPinnedWidth', `${dimensionsState.leftPinnedWidth}px`);
set('--DataGrid-rightPinnedWidth', `${dimensionsState.rightPinnedWidth}px`);
set('--DataGrid-headerHeight', `${dimensionsState.headerHeight}px`);
set('--DataGrid-headersTotalHeight', `${dimensionsState.headersTotalHeight}px`);
set('--DataGrid-topContainerHeight', `${dimensionsState.topContainerHeight}px`);
set('--DataGrid-bottomContainerHeight', `${dimensionsState.bottomContainerHeight}px`);
set('--height', `${dimensionsState.rowHeight}px`);
}, [root, dimensionsState]);

const isFirstSizing = React.useRef(true);
const handleResize = React.useCallback<GridEventListener<'resize'>>(
Expand Down