11'use client' ;
22import * as React from 'react' ;
3+ import debounce from '@mui/utils/debounce' ;
34import { RefObject } from '@mui/x-internals/types' ;
45import { isDeepEqual } from '@mui/x-internals/isDeepEqual' ;
5- import { runIf } from '../../../utils/utils' ;
66import { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity' ;
77import { DataGridProcessedProps } from '../../../models/props/DataGridProps' ;
88import { GridPaginationModelApi , GridPaginationState } from './gridPaginationInterfaces' ;
@@ -277,6 +277,11 @@ export const useGridPaginationModel = (
277277 }
278278 } , [ apiRef ] ) ;
279279
280+ const debouncedNavigateToStart = React . useMemo (
281+ ( ) => debounce ( navigateToStart , 0 ) ,
282+ [ navigateToStart ] ,
283+ ) ;
284+
280285 /**
281286 * Resets the page only if the active items or quick filter has changed from the last time.
282287 * This is to avoid resetting the page when the filter model is changed
@@ -296,16 +301,16 @@ export const useGridPaginationModel = (
296301 }
297302
298303 previousFilterModel . current = currentActiveFilters ;
299- navigateToStart ( ) ;
304+ debouncedNavigateToStart ( ) ;
300305 } ,
301- [ apiRef , navigateToStart ] ,
306+ [ apiRef , debouncedNavigateToStart ] ,
302307 ) ;
303308
304309 useGridEvent ( apiRef , 'viewportInnerSizeChange' , handleUpdateAutoPageSize ) ;
305310 useGridEvent ( apiRef , 'paginationModelChange' , handlePaginationModelChange ) ;
306311 useGridEvent ( apiRef , 'rowCountChange' , handleRowCountChange ) ;
307- useGridEvent ( apiRef , 'sortModelChange' , runIf ( ! props . paginationModel , navigateToStart ) ) ;
308- useGridEvent ( apiRef , 'filterModelChange' , runIf ( ! props . paginationModel , handleFilterModelChange ) ) ;
312+ useGridEvent ( apiRef , 'sortModelChange' , debouncedNavigateToStart ) ;
313+ useGridEvent ( apiRef , 'filterModelChange' , handleFilterModelChange ) ;
309314
310315 /**
311316 * EFFECTS
0 commit comments