From a124300de82a98cc16392346bcf049ecc0f55ad9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:54:59 +0100 Subject: [PATCH] [DataGrid] Remove try/catch from `GridCell` due to performance issues (@lauri865) (#15621) Co-authored-by: Lauri --- .../src/components/cell/GridCell.tsx | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/x-data-grid/src/components/cell/GridCell.tsx b/packages/x-data-grid/src/components/cell/GridCell.tsx index 54511abba199..27bfb3635505 100644 --- a/packages/x-data-grid/src/components/cell/GridCell.tsx +++ b/packages/x-data-grid/src/components/cell/GridCell.tsx @@ -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'; @@ -196,19 +195,17 @@ const GridCell = React.forwardRef(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( - 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( + rowId, + field, + ); + result.api = apiRef.current; + return result; }, objectShallowCompare, );