@@ -10,6 +10,7 @@ import {
10
10
GridEditModes ,
11
11
useGridApiRef ,
12
12
GridApi ,
13
+ GridRow ,
13
14
} from '@mui/x-data-grid' ;
14
15
import {
15
16
getCell ,
@@ -190,7 +191,7 @@ describe('<DataGrid /> - Row Selection', () => {
190
191
expect ( getColumnHeaderCell ( 0 ) . querySelectorAll ( 'input' ) ) . to . have . length ( 1 ) ;
191
192
} ) ;
192
193
193
- it ( 'should check and uncheck when double clicking the row' , ( ) => {
194
+ it ( 'should check then uncheck when clicking twice the row' , ( ) => {
194
195
render ( < TestDataGridSelection checkboxSelection /> ) ;
195
196
expect ( getSelectedRowIds ( ) ) . to . deep . equal ( [ ] ) ;
196
197
expect ( getRow ( 0 ) . querySelector ( 'input' ) ) . to . have . property ( 'checked' , false ) ;
@@ -774,4 +775,54 @@ describe('<DataGrid /> - Row Selection', () => {
774
775
expect ( getSelectedRowIds ( ) ) . to . deep . equal ( [ ] ) ;
775
776
} ) ;
776
777
} ) ;
778
+
779
+ describe ( 'performance' , ( ) => {
780
+ it ( 'should not rerender unrelated rows' , ( ) => {
781
+ // TODO: remove this requirement, find ways to scope down react tree rerenders.
782
+ const MemoizedRow = React . memo ( GridRow ) ;
783
+
784
+ // Couldn't use <RenderCounter> because we need to track multiple components
785
+ let commits : any [ ] = [ ] ;
786
+ function CustomCell ( props : any ) {
787
+ React . useEffect ( ( ) => {
788
+ commits . push ( {
789
+ rowId : props . id ,
790
+ } ) ;
791
+ } ) ;
792
+ return < div > Hello</ div > ;
793
+ }
794
+
795
+ render (
796
+ < div style = { { width : 300 , height : 300 } } >
797
+ < DataGrid
798
+ columns = { [
799
+ { field : 'id' , headerName : 'id' , type : 'number' } ,
800
+ {
801
+ field : 'currencyPair' ,
802
+ headerName : 'Currency Pair' ,
803
+ renderCell : ( params ) => < CustomCell { ...params } /> ,
804
+ } ,
805
+ ] }
806
+ slots = { {
807
+ row : MemoizedRow ,
808
+ } }
809
+ rows = { [
810
+ { id : 0 , currencyPair : 'USDGBP' } ,
811
+ { id : 1 , currencyPair : 'USDEUR' } ,
812
+ ] }
813
+ autoHeight = { isJSDOM }
814
+ checkboxSelection
815
+ />
816
+ </ div > ,
817
+ ) ;
818
+ expect ( getSelectedRowIds ( ) ) . to . deep . equal ( [ ] ) ;
819
+ expect ( getRow ( 0 ) . querySelector ( 'input' ) ) . to . have . property ( 'checked' , false ) ;
820
+ commits = [ ] ;
821
+ fireEvent . click ( getCell ( 0 , 1 ) ) ;
822
+ expect ( getSelectedRowIds ( ) ) . to . deep . equal ( [ 0 ] ) ;
823
+ expect ( getRow ( 0 ) . querySelector ( 'input' ) ) . to . have . property ( 'checked' , true ) ;
824
+ // It shouldn't rerender rowId 1
825
+ expect ( commits ) . to . deep . equal ( [ { rowId : 0 } ] ) ;
826
+ } ) ;
827
+ } ) ;
777
828
} ) ;
0 commit comments