🐛 Fix Table inifinite loop issue

This commit is contained in:
afc163 2019-11-05 00:40:03 +08:00 committed by 偏右
parent 715814291b
commit 0bdf682a80
2 changed files with 21 additions and 1 deletions

View File

@ -284,7 +284,7 @@ class Table<T> extends React.Component<InternalTableProps<T>, TableState<T>> {
const { columns, sortColumn, sortOrder } = this.state;
if (this.getSortOrderColumns(columns).length > 0) {
const sortState = this.getSortStateFromColumns(columns);
if (sortState.sortColumn !== sortColumn || sortState.sortOrder !== sortOrder) {
if (!isSameColumn(sortState.sortColumn, sortColumn) || sortState.sortOrder !== sortOrder) {
this.setState(sortState);
}
}

View File

@ -676,4 +676,24 @@ describe('Table.sorter', () => {
expect(renderedNames(wrapper)).toEqual(['Brown', 'Green', 'Mike', 'Alex', 'Petter', 'Zoe']);
});
// https://github.com/ant-design/ant-design/issues/19443
it('should not being inifinite loop when using Table.Column with sortOrder', () => {
class Demo extends React.Component {
componentDidMount() {
this.setState({});
}
render() {
return (
<Table dataSource={[]}>
<Table.Column title="Age" dataIndex="age" sorter sortOrder="ascend" key="age" />
</Table>
);
}
}
expect(() => {
mount(<Demo />);
}).not.toThrow();
});
});