Skip to content

Commit

Permalink
refactor: reduce virtualizer physical element count (#2912) (#2916)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored Oct 22, 2021
1 parent 65026e3 commit 47ee193
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/vaadin-grid/test/filtering.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('filtering', () => {
grid._filters[0].value = '99';
flushFilters(grid);
flushGrid(grid);
expect(grid.$.items.querySelectorAll('tr:not([hidden])')).to.have.length(19);
expect(grid.$.items.querySelectorAll('tr:not([hidden])')).to.have.length(18);
});

it('should not overflow filter text field', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class IronListAdapter {
this.scrollContainer = scrollContainer;
this.elementsContainer = elementsContainer || scrollContainer;
this.reorderElements = reorderElements;
// Iron-list uses this value to determine how many pages of elements to render
this._maxPages = 1.3;

this.__safari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

Expand Down
2 changes: 1 addition & 1 deletion packages/vaadin-virtual-list/test/reorder-elements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('reorder elements', () => {
resolve(mutations.flatMap((record) => [...record.removedNodes]));
}).observe(elementsContainer, { childList: true });

virtualizer.scrollToIndex(Math.ceil(elementsContainer.childElementCount / 2));
virtualizer.scrollToIndex(Math.ceil(elementsContainer.childElementCount / 3));

if (!skipFlush) {
virtualizer.flush();
Expand Down
10 changes: 9 additions & 1 deletion packages/vaadin-virtual-list/test/virtualizer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('virtualizer', () => {

// Decrease the size so that we end up at the top of the list
updateElement.resetHistory();
virtualizer.size = 10;
virtualizer.size = 5;
const postResizeUpdatedIndexes = updateElement.getCalls().map((call) => call.args[1]);

expect(postResizeUpdatedIndexes).not.to.include.members(updatedIndexes);
Expand Down Expand Up @@ -241,6 +241,14 @@ describe('virtualizer', () => {
expect(elementsContainer.childElementCount).to.equal(initialCount);
});

it('should initially have a decent amount of physical elements', () => {
const initialCount = elementsContainer.childElementCount;
const viewportHeight = scrollTarget.offsetHeight;
const itemHeight = elementsContainer.querySelector('#item-0').offsetHeight;
const expectedCount = Math.ceil((viewportHeight / itemHeight) * 1.3) + 1;
expect(initialCount).not.to.be.above(expectedCount);
});

describe('lazy rendering', () => {
let render = false;

Expand Down

0 comments on commit 47ee193

Please sign in to comment.