Skip to content

Commit

Permalink
fix(Table): can't find unmounted component
Browse files Browse the repository at this point in the history
  • Loading branch information
youluna committed Dec 19, 2018
1 parent 73ffca3 commit f004b52
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
39 changes: 35 additions & 4 deletions src/table/lock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,14 @@ export default function lock(BaseComponent) {

getWrapperNode(type) {
type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
return findDOMNode(this.refs[`lock${type}`]);
try {
// in case of finding an unmounted component due to cached data
// need to clear refs of table when dataSource Changed
// use try catch for temporary
return findDOMNode(this.refs[`lock${type}`]);
} catch (error) {
return null;
}
}

getFirstNormalCellNode(index) {
Expand All @@ -443,19 +450,43 @@ export default function lock(BaseComponent) {
getRowNode(index, type) {
type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
const table = this[`table${type}Inc`];
return findDOMNode(table.getRowRef(index));

try {
// in case of finding an unmounted component due to cached data
// need to clear refs of table when dataSource Changed
// use try catch for temporary
return findDOMNode(table.getRowRef(index));
} catch (error) {
return null;
}
}

getHeaderCellNode(index, i, type) {
type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
const table = this[`table${type}Inc`];
return findDOMNode(table.getHeaderCellRef(index, i));

try {
// in case of finding an unmounted component due to cached data
// need to clear refs of table when dataSource Changed
// use try catch for temporary
return findDOMNode(table.getHeaderCellRef(index, i));
} catch (error) {
return null;
}
}

getCellNode(index, i, type) {
type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
const table = this[`table${type}Inc`];
return findDOMNode(table.getCellRef(index, i));

try {
// in case of finding an unmounted component due to cached data
// need to clear refs of table when dataSource Changed
// use try catch for temporary
return findDOMNode(table.getCellRef(index, i));
} catch (error) {
return null;
}
}

render() {
Expand Down
11 changes: 9 additions & 2 deletions src/table/virtual.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function virtual(BaseComponent) {
if (this.state.rowHeight && 'rowHeight' in nextProps) {
const row = this.getRowNode();
const rowClientHeight = row && row.clientHeight;
if (rowClientHeight !== this.state.rowHeight) {
if (rowClientHeight && rowClientHeight !== this.state.rowHeight) {
this.setState({
rowHeight: rowClientHeight
});
Expand Down Expand Up @@ -240,7 +240,14 @@ export default function virtual(BaseComponent) {
}

getRowNode() {
return findDOMNode(this.tableInc.getRowRef(0));
try {
// in case of finding an unmounted component due to cached data
// need to clear refs of this.tableInc when dataSource Changed
// use try catch for temporary
return findDOMNode(this.tableInc.getRowRef(0));
} catch (error) {
return null;
}
}

render() {
Expand Down

0 comments on commit f004b52

Please sign in to comment.