Skip to content

Commit c7f0e54

Browse files
authored
fix: shouldCellUpdate should not ignore className (#669)
1 parent 0650be9 commit c7f0e54

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Cell/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ function Cell<RecordType extends DefaultRecordType>(
216216
const RefCell = React.forwardRef<any, CellProps<any>>(Cell);
217217
RefCell.displayName = 'Cell';
218218

219+
const comparePropList: (keyof CellProps<any>)[] = ['expanded', 'className'];
220+
219221
const MemoCell = React.memo(RefCell, (prev: CellProps<any>, next: CellProps<any>) => {
220222
if (next.shouldCellUpdate) {
221223
return (
222224
// Additional handle of expanded logic
223-
prev.expanded === next.expanded &&
225+
comparePropList.every(propName => prev[propName] === next[propName]) &&
224226
// User control update logic
225227
!next.shouldCellUpdate(next.record, prev.record)
226228
);

tests/Cell.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,32 @@ describe('Table.Cell', () => {
4242
expect(reRenderTime).toEqual(0);
4343
}
4444
});
45+
46+
it('shouldCellUpdate not block className', () => {
47+
let reRenderTime = 0;
48+
49+
const getColumns = (props?: object) => [
50+
{
51+
shouldCellUpdate: (record, prevRecord) => prevRecord.key !== record.key,
52+
dataIndex: 'key',
53+
render: value => {
54+
reRenderTime += 1;
55+
return value;
56+
},
57+
...props,
58+
},
59+
];
60+
61+
const wrapper = mount(<Table data={[{ key: 'light' }]} columns={getColumns()} />);
62+
63+
// Update className should re-render
64+
reRenderTime = 0;
65+
for (let i = 0; i < 10; i += 1) {
66+
wrapper.setProps({
67+
columns: getColumns({ className: 'test' }),
68+
});
69+
}
70+
71+
expect(reRenderTime).toEqual(1);
72+
});
4573
});

0 commit comments

Comments
 (0)