Skip to content

Commit

Permalink
fix: Double-check optimal size before adding new physical rows (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored Jun 15, 2020
1 parent 7acf128 commit 8cbae17
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
"iron-a11y-keys-behavior": "^v2.0.0",
"iron-a11y-announcer": "^v2.0.0",
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.6.1",
"vaadin-checkbox": "vaadin/vaadin-checkbox#^2.4.0-alpha1",
"vaadin-text-field": "vaadin/vaadin-text-field#^2.7.0-alpha1",
"vaadin-checkbox": "vaadin/vaadin-checkbox#~2.4.0-alpha3",
"vaadin-text-field": "vaadin/vaadin-text-field#~2.7.0-alpha4",
"vaadin-lumo-styles": "vaadin/vaadin-lumo-styles#^1.6.0",
"vaadin-material-styles": "vaadin/vaadin-material-styles#^1.3.2",
"vaadin-element-mixin": "vaadin/vaadin-element-mixin#^2.4.1"
Expand Down
2 changes: 1 addition & 1 deletion src/vaadin-grid-scroller.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,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();
Expand Down
21 changes: 21 additions & 0 deletions test/physical-count.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
</script>

Expand Down

0 comments on commit 8cbae17

Please sign in to comment.