Skip to content

Commit

Permalink
fix(Table): prevent crash when dataSource is undefined, close #4073
Browse files Browse the repository at this point in the history
  • Loading branch information
lakerswgq committed Sep 8, 2022
1 parent 8b7b3d4 commit cc1817a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
"react-lifecycles-compat": "^3.0.4",
"react-transition-group": "^2.2.1",
"resize-observer-polyfill": "^1.5.1",
"semver": "^7.3.5",
"shallow-element-equals": "^1.0.1"
},
"devDependencies": {
Expand Down Expand Up @@ -243,7 +242,8 @@
"urllib": "^2.36.1",
"webpack": "^3.0.0",
"webpack-dev-server": "^2.x",
"whatwg-fetch": "^2.0.3"
"whatwg-fetch": "^2.0.3",
"semver": "^7.3.5"
},
"peerDependencies": {
"@alifd/meet-react": "^2.0.0",
Expand Down
12 changes: 6 additions & 6 deletions src/table/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -829,21 +829,21 @@ class Table extends React.Component {
others.dir = 'rtl';
}

const loadingcls = classnames({
[`${prefix}table-loading-content`]: true,
});

return (
const content = (
<div
className={cls}
style={style}
ref={ref || this.getTableEl}
{...obj.pickOthers(Object.keys(Table.propTypes), others)}
>
{table}
{loading ? <Loading className={loadingcls} /> : null}
</div>
);
if (loading) {
const loadingClassName = `${prefix}table-loading`;
return <LoadingComponent className={loadingClassName}>{content}</LoadingComponent>;
}
return content;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/table/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ConfigProvider from '../config-provider';
import Base from './base-pre';
import Base from './base';
import tree from './tree';
import fixed from './fixed';
import selection from './selection';
Expand Down
13 changes: 13 additions & 0 deletions test/table/issue-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,4 +1267,17 @@ describe('Issue', () => {

assert(container.querySelectorAll('.my-table').length >= 1);
})

it('should not crash when dataSource is undefined, close #4073', () => {
const container = document.createElement('div');
document.body.appendChild(container);

ReactDOM.render(<Table >
<Table.Column title="Id" lock htmlTitle="Unique Id" dataIndex="id"/>
<Table.Column title="Title" dataIndex="title.name" />
<Table.Column title="Time" dataIndex="time"/>
</Table>, container);

assert(container.querySelector('.next-table-empty'))
})
});

0 comments on commit cc1817a

Please sign in to comment.