From 2a7d53779d2eb6e4485fe78e24d72dc816f2ff98 Mon Sep 17 00:00:00 2001 From: Tomi Virkki Date: Mon, 15 Jun 2020 10:06:04 +0300 Subject: [PATCH] fix: Double-check optimal size before adding new physical rows (#1755) --- src/vaadin-grid-scroller.html | 2 +- test/physical-count.html | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/vaadin-grid-scroller.html b/src/vaadin-grid-scroller.html index d6d6bf233..ba60b03c2 100644 --- a/src/vaadin-grid-scroller.html +++ b/src/vaadin-grid-scroller.html @@ -190,7 +190,7 @@ estimatedMissingRowCount = Math.max(0, this._effectiveSize - this._physicalCount); } - if (this._physicalSize && estimatedMissingRowCount > 0) { + if (this._physicalSize && estimatedMissingRowCount > 0 && this._optPhysicalSize !== Infinity) { super._increasePoolIfNeeded(estimatedMissingRowCount); // Ensure the rows are in order after increasing pool this.__reorderChildNodes(); diff --git a/test/physical-count.html b/test/physical-count.html index dbd4ffa95..090977c99 100644 --- a/test/physical-count.html +++ b/test/physical-count.html @@ -140,7 +140,28 @@ expect(spy).not.to.be.called; }); + it('should not add unlimited amount of physical rows', () => { + const itemCount = 50; + grid.items = buildDataSet(itemCount); + flushGrid(grid); + + // Repro for a really special bug: + + // 1: notifyResize will trigger _increasePoolIfNeeded + grid.notifyResize(); + // 2: Hide grid + grid.hidden = true; + // 3: notifyResize will trigger updateViewportBoundaries which sets _viewPortHeight to 0 because grid is not rendered + grid.notifyResize(); + // 4: Restore grid to render tree + grid.hidden = false; + // 5: Finally flush the grid, and finish the async callback started at phase 1. + // _optPhysicalSize will be Infinity at this point so unlimited amount of rows would get added! + // Only thing that limits it is the grid.items count. + flushGrid(grid); + expect(grid.$.items.childElementCount).to.be.below(itemCount); + }); });