Skip to content

Commit

Permalink
🐛 Fix Table inifinite loop issue
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Nov 4, 2019
1 parent 7158142 commit 0bdf682
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
20 changes: 20 additions & 0 deletions components/table/__tests__/Table.sorter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 0bdf682

Please sign in to comment.