Skip to content

Commit

Permalink
Cherrypick: Flush debounceIncreasePool on loadPage (#2131) (#2132)
Browse files Browse the repository at this point in the history
fix: Flush debounceIncreasePool on loadPage

cherrypick: #2131
fixes: #2107
Warranty: Fixes TreeGrid regression where blank areas are displayed when an initial scroll happens.
  • Loading branch information
tulioag authored Feb 18, 2021
1 parent 0271abd commit 38a01c5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/vaadin-grid-data-provider-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export const DataProviderMixin = (superClass) =>
filters: this._mapFilters(),
parentItem: cache.parentItem
};

this._debounceIncreasePool && this._debounceIncreasePool.flush();
this.dataProvider(params, (items, size) => {
if (size !== undefined) {
cache.size = size;
Expand Down
2 changes: 1 addition & 1 deletion test/data-provider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ describe('data provider', () => {
// Effective size should change in between the data requests
expect(renderSpy.called).to.be.true;
expect(increasePoolSpy.callCount).to.above(1);
expect(updateItemSpy.callCount).to.be.below(90);
expect(updateItemSpy.callCount).to.be.below(180);
});

it('should keep item expanded on itemIdPath change', () => {
Expand Down
37 changes: 37 additions & 0 deletions test/scroll-to-index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const fixtures = {
<template>[[index]]</template>
</vaadin-grid-column>
</vaadin-grid>
`,
treeGrid: `
<vaadin-grid style="width: 200px; height: 500px;">
<vaadin-grid-tree-column path="name" header="foo" item-has-children-path="hasChildren"></vaadin-grid-tree-column>
</vaadin-grid>
`
};

Expand Down Expand Up @@ -203,4 +208,36 @@ describe('scroll to index', () => {
expect(grid.$.items.children[0]._item.index).to.equal(0);
});
});
describe('Tree grid', () => {
// Issue https://github.com/vaadin/vaadin-grid/issues/2107
it('should display correctly when scrolled to bottom immediately after setting dataProvider', (done) => {
const grid = fixtureSync(fixtures.treeGrid);
grid.size = 1;
const numberOfChidren = 250;
grid.itemIdPath = 'name';
const PARENT = { name: 'PARENT', hasChildren: true };
grid.dataProvider = ({ page, parentItem }, cb) => {
setTimeout(() => {
if (!parentItem) {
cb([PARENT], 1);
return;
}

const offset = page * grid.pageSize;
cb(
[...new Array(grid.pageSize)].map((_, index) => {
return { name: 'Child ' + (offset + index), hasChildren: false };
}),
numberOfChidren
);
if (page > 0) {
expect(grid._physicalCount).to.be.above(10);
done();
}
});
};
grid.expandedItems = [PARENT];
grid.scrollToIndex(250);
});
});
});

0 comments on commit 38a01c5

Please sign in to comment.