Skip to content

Commit

Permalink
Merge pull request #5603 from marmelab/fix-optimized-datagrid-blocking
Browse files Browse the repository at this point in the history
Fix optimized Datagrid freezes when using Expand
  • Loading branch information
djhi authored Nov 30, 2020
2 parents 20ae465 + bd95291 commit 823cbdc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
3 changes: 0 additions & 3 deletions examples/simple/src/posts/ResetViewsButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import VisibilityOff from '@material-ui/icons/VisibilityOff';
import {
useUpdateMany,
useRefresh,
useNotify,
useUnselectAll,
Button,
Expand All @@ -13,7 +12,6 @@ import {
const ResetViewsButton = ({ resource, selectedIds }) => {
const notify = useNotify();
const unselectAll = useUnselectAll();
const refresh = useRefresh();
const [updateMany, { loading }] = useUpdateMany(
resource,
selectedIds,
Expand All @@ -28,7 +26,6 @@ const ResetViewsButton = ({ resource, selectedIds }) => {
true
);
unselectAll(resource);
refresh();
},
onFailure: error =>
notify(
Expand Down
18 changes: 14 additions & 4 deletions packages/ra-ui-materialui/src/list/datagrid/DatagridBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cloneElement, memo, FC, ReactElement } from 'react';
import PropTypes from 'prop-types';
import { TableBody, TableBodyProps } from '@material-ui/core';
import classnames from 'classnames';
import isEqual from 'lodash/isEqual';
import { shallowEqual } from 'react-redux';
import { Identifier, Record, RecordMap } from 'ra-core';

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

const areEqual = (prevProps, nextProps) => {
const { children: _, ...prevPropsWithoutChildren } = prevProps;
const { children: __, ...nextPropsWithoutChildren } = nextProps;
return isEqual(prevPropsWithoutChildren, nextPropsWithoutChildren);
const {
children: _1,
expand: _2,
row: _3,
...prevPropsWithoutChildren
} = prevProps;
const {
children: _4,
expand: _5,
row: _6,
...nextPropsWithoutChildren
} = nextProps;
return shallowEqual(prevPropsWithoutChildren, nextPropsWithoutChildren);
};

export const PureDatagridBody = memo(DatagridBody, areEqual);
Expand Down
8 changes: 4 additions & 4 deletions packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
Record,
useResourceContext,
} from 'ra-core';
import isEqual from 'lodash/isEqual';
import { shallowEqual } from 'react-redux';
import { useHistory } from 'react-router-dom';

import DatagridCell from './DatagridCell';
Expand Down Expand Up @@ -265,9 +265,9 @@ export type RowClickFunction = (
) => string;

const areEqual = (prevProps, nextProps) => {
const { children: _, ...prevPropsWithoutChildren } = prevProps;
const { children: __, ...nextPropsWithoutChildren } = nextProps;
return isEqual(prevPropsWithoutChildren, nextPropsWithoutChildren);
const { children: _1, expand: _2, ...prevPropsWithoutChildren } = prevProps;
const { children: _3, expand: _4, ...nextPropsWithoutChildren } = nextProps;
return shallowEqual(prevPropsWithoutChildren, nextPropsWithoutChildren);
};

export const PureDatagridRow = memo(DatagridRow, areEqual);
Expand Down

0 comments on commit 823cbdc

Please sign in to comment.