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] Remove try/catch from GridCell due to performance issues (@lauri865) #15621

Merged
merged 1 commit into from
Nov 29, 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
23 changes: 10 additions & 13 deletions packages/x-data-grid/src/components/cell/GridCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { useGridSelector, objectShallowCompare } from '../../hooks/utils/useGrid
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { gridFocusCellSelector } from '../../hooks/features/focus/gridFocusStateSelector';
import { MissingRowIdError } from '../../hooks/features/rows/useGridParamsApi';
import type { DataGridProcessedProps } from '../../models/props/DataGridProps';
import { shouldCellShowLeftBorder, shouldCellShowRightBorder } from '../../utils/cellBorderUtils';
import { GridPinnedColumnPosition } from '../../hooks/features/columns/gridColumnsInterfaces';
Expand Down Expand Up @@ -196,19 +195,17 @@ const GridCell = React.forwardRef<HTMLDivElement, GridCellProps>(function GridCe
// This is required because `.getCellParams` tries to get the `state.rows.tree` entry
// associated with `rowId`/`fieldId`, but this selector runs after the state has been
// updated, while `rowId`/`fieldId` reference an entry in the old state.
try {
const result = apiRef.current.getCellParams<any, any, any, GridTreeNodeWithRender>(
rowId,
field,
);
result.api = apiRef.current;
return result;
} catch (error) {
if (error instanceof MissingRowIdError) {
return EMPTY_CELL_PARAMS;
}
throw error;
const row = apiRef.current.getRow(rowId);
if (!row) {
return EMPTY_CELL_PARAMS;
}

const result = apiRef.current.getCellParams<any, any, any, GridTreeNodeWithRender>(
rowId,
field,
);
result.api = apiRef.current;
return result;
},
objectShallowCompare,
);
Expand Down