Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Add assertion about checkbox rerenders #8974

Merged
merged 1 commit into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
GridEditModes,
useGridApiRef,
GridApi,
GridRow,
} from '@mui/x-data-grid';
import {
getCell,
Expand Down Expand Up @@ -190,7 +191,7 @@ describe('<DataGrid /> - Row Selection', () => {
expect(getColumnHeaderCell(0).querySelectorAll('input')).to.have.length(1);
});

it('should check and uncheck when double clicking the row', () => {
it('should check then uncheck when clicking twice the row', () => {
render(<TestDataGridSelection checkboxSelection />);
expect(getSelectedRowIds()).to.deep.equal([]);
expect(getRow(0).querySelector('input')).to.have.property('checked', false);
Expand Down Expand Up @@ -774,4 +775,54 @@ describe('<DataGrid /> - Row Selection', () => {
expect(getSelectedRowIds()).to.deep.equal([]);
});
});

describe('performance', () => {
it('should not rerender unrelated rows', () => {
// TODO: remove this requirement, find ways to scope down react tree rerenders.
const MemoizedRow = React.memo(GridRow);

// Couldn't use <RenderCounter> because we need to track multiple components
let commits: any[] = [];
function CustomCell(props: any) {
React.useEffect(() => {
commits.push({
rowId: props.id,
});
});
return <div>Hello</div>;
}

render(
<div style={{ width: 300, height: 300 }}>
<DataGrid
columns={[
{ field: 'id', headerName: 'id', type: 'number' },
{
field: 'currencyPair',
headerName: 'Currency Pair',
renderCell: (params) => <CustomCell {...params} />,
},
]}
slots={{
row: MemoizedRow,
}}
rows={[
{ id: 0, currencyPair: 'USDGBP' },
{ id: 1, currencyPair: 'USDEUR' },
]}
autoHeight={isJSDOM}
checkboxSelection
/>
</div>,
);
expect(getSelectedRowIds()).to.deep.equal([]);
expect(getRow(0).querySelector('input')).to.have.property('checked', false);
commits = [];
fireEvent.click(getCell(0, 1));
expect(getSelectedRowIds()).to.deep.equal([0]);
expect(getRow(0).querySelector('input')).to.have.property('checked', true);
// It shouldn't rerender rowId 1
expect(commits).to.deep.equal([{ rowId: 0 }]);
Comment on lines +824 to +825
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test runs in < 100ms (it's not super fast, but I guess it's because of the data grid). It fails in v6.4.0 (without #8942) with this error:

Screenshot 2023-05-13 at 14 31 25

});
});
});