Skip to content

Commit 5a4a071

Browse files
author
frankqian
authored
Merge pull request alibaba-fusion#99 from youluna/master
fix(Table): can't find unmount component
2 parents 6023722 + f004b52 commit 5a4a071

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

src/table/lock.jsx

+35-4
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,14 @@ export default function lock(BaseComponent) {
426426

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

432439
getFirstNormalCellNode(index) {
@@ -443,19 +450,43 @@ export default function lock(BaseComponent) {
443450
getRowNode(index, type) {
444451
type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
445452
const table = this[`table${type}Inc`];
446-
return findDOMNode(table.getRowRef(index));
453+
454+
try {
455+
// in case of finding an unmounted component due to cached data
456+
// need to clear refs of table when dataSource Changed
457+
// use try catch for temporary
458+
return findDOMNode(table.getRowRef(index));
459+
} catch (error) {
460+
return null;
461+
}
447462
}
448463

449464
getHeaderCellNode(index, i, type) {
450465
type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
451466
const table = this[`table${type}Inc`];
452-
return findDOMNode(table.getHeaderCellRef(index, i));
467+
468+
try {
469+
// in case of finding an unmounted component due to cached data
470+
// need to clear refs of table when dataSource Changed
471+
// use try catch for temporary
472+
return findDOMNode(table.getHeaderCellRef(index, i));
473+
} catch (error) {
474+
return null;
475+
}
453476
}
454477

455478
getCellNode(index, i, type) {
456479
type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
457480
const table = this[`table${type}Inc`];
458-
return findDOMNode(table.getCellRef(index, i));
481+
482+
try {
483+
// in case of finding an unmounted component due to cached data
484+
// need to clear refs of table when dataSource Changed
485+
// use try catch for temporary
486+
return findDOMNode(table.getCellRef(index, i));
487+
} catch (error) {
488+
return null;
489+
}
459490
}
460491

461492
render() {

src/table/virtual.jsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default function virtual(BaseComponent) {
103103
if (this.state.rowHeight && 'rowHeight' in nextProps) {
104104
const row = this.getRowNode();
105105
const rowClientHeight = row && row.clientHeight;
106-
if (rowClientHeight !== this.state.rowHeight) {
106+
if (rowClientHeight && rowClientHeight !== this.state.rowHeight) {
107107
this.setState({
108108
rowHeight: rowClientHeight
109109
});
@@ -240,7 +240,14 @@ export default function virtual(BaseComponent) {
240240
}
241241

242242
getRowNode() {
243-
return findDOMNode(this.tableInc.getRowRef(0));
243+
try {
244+
// in case of finding an unmounted component due to cached data
245+
// need to clear refs of this.tableInc when dataSource Changed
246+
// use try catch for temporary
247+
return findDOMNode(this.tableInc.getRowRef(0));
248+
} catch (error) {
249+
return null;
250+
}
244251
}
245252

246253
render() {

0 commit comments

Comments
 (0)