Skip to content

Commit

Permalink
[DataGrid] Remove try/catch from GridCell due to performance issues (
Browse files Browse the repository at this point in the history
…@lauri865) (#15621)

Co-authored-by: Lauri <lauri.lehtmaa@gmail.com>
  • Loading branch information
github-actions[bot] and lauri865 authored Nov 29, 2024
1 parent 72926cb commit a124300
Showing 1 changed file with 10 additions and 13 deletions.
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

0 comments on commit a124300

Please sign in to comment.