From c39b7347a96cf13e25d059a691f966daa6fb65ff Mon Sep 17 00:00:00 2001 From: Bilal Shafi Date: Thu, 3 Oct 2024 14:27:08 +0500 Subject: [PATCH] [DataGridPro] Fix row pre-processing running with a stale data source (#14810) --- .../x-data-grid/src/hooks/features/rows/useGridRows.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 775962e697bc4..bd89c281f7292 100644 --- a/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts +++ b/packages/x-data-grid/src/hooks/features/rows/useGridRows.ts @@ -1,4 +1,5 @@ import * as React from 'react'; +import useLazyRef from '@mui/utils/useLazyRef'; import { GridEventListener } from '../../../models/events'; import { DataGridProcessedProps } from '../../../models/props/DataGridProps'; import { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity'; @@ -73,6 +74,7 @@ export const useGridRows = ( | 'pagination' | 'paginationMode' | 'loading' + | 'unstable_dataSource' >, ): void => { if (process.env.NODE_ENV !== 'production') { @@ -536,15 +538,20 @@ export const useGridRows = ( throttledRowsChange, ]); + const previousDataSource = useLazyRef(() => props.unstable_dataSource); const handleStrategyProcessorChange = React.useCallback< GridEventListener<'activeStrategyProcessorChange'> >( (methodName) => { + if (props.unstable_dataSource && props.unstable_dataSource !== previousDataSource.current) { + previousDataSource.current = props.unstable_dataSource; + return; + } if (methodName === 'rowTreeCreation') { groupRows(); } }, - [groupRows], + [groupRows, previousDataSource, props.unstable_dataSource], ); const handleStrategyActivityChange = React.useCallback<