Skip to content

Commit 4de8671

Browse files
authored
chore: do not clear row height cache automatically (#192)
1 parent 98010b5 commit 4de8671

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## NEXT VERSION
44

5+
- chore: do not clear row height cache automatically
6+
57
## v1.10.4 (2020-07-02)
68

79
- fix: flicker on expanding in dynamic mode

src/BaseTable.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class BaseTable extends React.PureComponent {
207207
}
208208

209209
/**
210-
* Reset cached row heights after a specific rowIndex, should be used only in dynamic mode(estimatedRowHeight is provided)
210+
* Reset cached offsets for positioning after a specific rowIndex, should be used only in dynamic mode(estimatedRowHeight is provided)
211211
*/
212212
resetAfterRowIndex(rowIndex = 0, shouldForceUpdate = true) {
213213
if (!this.props.estimatedRowHeight) return;
@@ -217,6 +217,20 @@ class BaseTable extends React.PureComponent {
217217
this.rightTable && this.rightTable.resetAfterRowIndex(rowIndex, shouldForceUpdate);
218218
}
219219

220+
/**
221+
* Reset row height cache, useful if `data` changed entirely, should be used only in dynamic mode(estimatedRowHeight is provided)
222+
*/
223+
resetRowHeightCache() {
224+
if (!this.props.estimatedRowHeight) return;
225+
226+
this._resetIndex = null;
227+
this._rowHeightMapBuffer = {};
228+
this._rowHeightMap = {};
229+
this._mainRowHeightMap = {};
230+
this._leftRowHeightMap = {};
231+
this._rightRowHeightMap = {};
232+
}
233+
220234
/**
221235
* Scroll to the specified offset.
222236
* Useful for animating position changes.
@@ -673,7 +687,7 @@ class BaseTable extends React.PureComponent {
673687

674688
const _data = expandColumnKey ? this._flattenOnKeys(data, this.getExpandedRowKeys(), this.props.rowKey) : data;
675689
if (this._data !== _data) {
676-
this._resetRowHeightCache();
690+
this.resetAfterRowIndex(0, false);
677691
this._data = _data;
678692
}
679693
// should be after `this._data` assigned
@@ -989,17 +1003,6 @@ class BaseTable extends React.PureComponent {
9891003
this._rowHeightMapBuffer[rowKey] = size;
9901004
this._updateRowHeights();
9911005
}
992-
993-
_resetRowHeightCache() {
994-
if (!this.props.estimatedRowHeight) return;
995-
996-
this._resetIndex = null;
997-
this._rowHeightMapBuffer = {};
998-
this._rowHeightMap = {};
999-
this._mainRowHeightMap = {};
1000-
this._leftRowHeightMap = {};
1001-
this._rightRowHeightMap = {};
1002-
}
10031006
}
10041007

10051008
BaseTable.Column = Column;

website/src/examples/dynamic-row-heights.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ export default class App extends React.Component {
182182
>
183183
Toggle columns
184184
</button>
185+
<button
186+
onClick={() => {
187+
this.setState({
188+
data: [dataGenerator(), ...data],
189+
})
190+
}}
191+
>
192+
Add item to top
193+
</button>
185194
<Table
186195
fixed
187196
selectable

0 commit comments

Comments
 (0)