Skip to content

Commit 823cbdc

Browse files
authored
Merge pull request #5603 from marmelab/fix-optimized-datagrid-blocking
Fix optimized Datagrid freezes when using Expand
2 parents 20ae465 + bd95291 commit 823cbdc

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

examples/simple/src/posts/ResetViewsButton.js

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
33
import VisibilityOff from '@material-ui/icons/VisibilityOff';
44
import {
55
useUpdateMany,
6-
useRefresh,
76
useNotify,
87
useUnselectAll,
98
Button,
@@ -13,7 +12,6 @@ import {
1312
const ResetViewsButton = ({ resource, selectedIds }) => {
1413
const notify = useNotify();
1514
const unselectAll = useUnselectAll();
16-
const refresh = useRefresh();
1715
const [updateMany, { loading }] = useUpdateMany(
1816
resource,
1917
selectedIds,
@@ -28,7 +26,6 @@ const ResetViewsButton = ({ resource, selectedIds }) => {
2826
true
2927
);
3028
unselectAll(resource);
31-
refresh();
3229
},
3330
onFailure: error =>
3431
notify(

packages/ra-ui-materialui/src/list/datagrid/DatagridBody.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cloneElement, memo, FC, ReactElement } from 'react';
33
import PropTypes from 'prop-types';
44
import { TableBody, TableBodyProps } from '@material-ui/core';
55
import classnames from 'classnames';
6-
import isEqual from 'lodash/isEqual';
6+
import { shallowEqual } from 'react-redux';
77
import { Identifier, Record, RecordMap } from 'ra-core';
88

99
import DatagridRow, { PureDatagridRow } from './DatagridRow';
@@ -135,9 +135,19 @@ export interface DatagridBodyProps extends Omit<TableBodyProps, 'classes'> {
135135
DatagridBody.muiName = 'TableBody';
136136

137137
const areEqual = (prevProps, nextProps) => {
138-
const { children: _, ...prevPropsWithoutChildren } = prevProps;
139-
const { children: __, ...nextPropsWithoutChildren } = nextProps;
140-
return isEqual(prevPropsWithoutChildren, nextPropsWithoutChildren);
138+
const {
139+
children: _1,
140+
expand: _2,
141+
row: _3,
142+
...prevPropsWithoutChildren
143+
} = prevProps;
144+
const {
145+
children: _4,
146+
expand: _5,
147+
row: _6,
148+
...nextPropsWithoutChildren
149+
} = nextProps;
150+
return shallowEqual(prevPropsWithoutChildren, nextPropsWithoutChildren);
141151
};
142152

143153
export const PureDatagridBody = memo(DatagridBody, areEqual);

packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
Record,
2626
useResourceContext,
2727
} from 'ra-core';
28-
import isEqual from 'lodash/isEqual';
28+
import { shallowEqual } from 'react-redux';
2929
import { useHistory } from 'react-router-dom';
3030

3131
import DatagridCell from './DatagridCell';
@@ -265,9 +265,9 @@ export type RowClickFunction = (
265265
) => string;
266266

267267
const areEqual = (prevProps, nextProps) => {
268-
const { children: _, ...prevPropsWithoutChildren } = prevProps;
269-
const { children: __, ...nextPropsWithoutChildren } = nextProps;
270-
return isEqual(prevPropsWithoutChildren, nextPropsWithoutChildren);
268+
const { children: _1, expand: _2, ...prevPropsWithoutChildren } = prevProps;
269+
const { children: _3, expand: _4, ...nextPropsWithoutChildren } = nextProps;
270+
return shallowEqual(prevPropsWithoutChildren, nextPropsWithoutChildren);
271271
};
272272

273273
export const PureDatagridRow = memo(DatagridRow, areEqual);

0 commit comments

Comments
 (0)