Skip to content

Commit 79266dd

Browse files
authored
fix: Double-check optimal size before adding new physical rows (#1755) (#1758)
1 parent 918086d commit 79266dd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/vaadin-grid-scroller.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
estimatedMissingRowCount = Math.max(0, this._effectiveSize - this._physicalCount);
191191
}
192192

193-
if (this._physicalSize && estimatedMissingRowCount > 0) {
193+
if (this._physicalSize && estimatedMissingRowCount > 0 && this._optPhysicalSize !== Infinity) {
194194
super._increasePoolIfNeeded(estimatedMissingRowCount);
195195
// Ensure the rows are in order after increasing pool
196196
this.__reorderChildNodes();

test/physical-count.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,28 @@
140140
expect(spy).not.to.be.called;
141141
});
142142

143+
it('should not add unlimited amount of physical rows', () => {
144+
const itemCount = 50;
145+
grid.items = buildDataSet(itemCount);
146+
flushGrid(grid);
147+
148+
// Repro for a really special bug:
149+
150+
// 1: notifyResize will trigger _increasePoolIfNeeded
151+
grid.notifyResize();
152+
// 2: Hide grid
153+
grid.hidden = true;
154+
// 3: notifyResize will trigger updateViewportBoundaries which sets _viewPortHeight to 0 because grid is not rendered
155+
grid.notifyResize();
156+
// 4: Restore grid to render tree
157+
grid.hidden = false;
158+
// 5: Finally flush the grid, and finish the async callback started at phase 1.
159+
// _optPhysicalSize will be Infinity at this point so unlimited amount of rows would get added!
160+
// Only thing that limits it is the grid.items count.
161+
flushGrid(grid);
143162

163+
expect(grid.$.items.childElementCount).to.be.below(itemCount);
164+
});
144165
});
145166
</script>
146167

0 commit comments

Comments
 (0)