From bb57c877457bdf77aa485fe0a70ff76e9f9fc2bb Mon Sep 17 00:00:00 2001 From: Bilal Shafi Date: Thu, 2 May 2024 16:18:36 +0500 Subject: [PATCH] [DataGrid] Fix rows not being recomputed on `props.rowCount` change (#12833) --- .../src/hooks/features/rows/useGridRows.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts b/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts index f9001be7054b0..aba863dad31c6 100644 --- a/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts +++ b/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts @@ -90,6 +90,7 @@ export const useGridRows = ( const currentPage = useGridVisibleRows(apiRef, props); const lastUpdateMs = React.useRef(Date.now()); + const lastRowCount = React.useRef(props.rowCount); const timeout = useTimeout(); const getRow = React.useCallback( @@ -594,6 +595,12 @@ export const useGridRows = ( return; } + let isRowCountPropUpdated = false; + if (props.rowCount !== lastRowCount.current) { + isRowCountPropUpdated = true; + lastRowCount.current = props.rowCount; + } + const areNewRowsAlreadyInState = apiRef.current.caches.rows.rowsBeforePartialUpdates === props.rows; const isNewLoadingAlreadyInState = @@ -625,8 +632,9 @@ export const useGridRows = ( apiRef.current.caches.rows.rowCountPropBeforePartialUpdates = props.rowCount; apiRef.current.forceUpdate(); } - - return; + if (!isRowCountPropUpdated) { + return; + } } logger.debug(`Updating all rows, new length ${props.rows.length}`);