Skip to content

Commit c3e75b8

Browse files
authored
fix: Flush debounceIncreasePool on loadPage if scrolling (#2131)
Fixes: #2107 Warranty: Fixes TreeGrid regression where blank areas are displayed when an initial scroll happens.
1 parent b9a0378 commit c3e75b8

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/vaadin-grid-data-provider-mixin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@
345345
filters: this._mapFilters(),
346346
parentItem: cache.parentItem
347347
};
348-
348+
this._debounceIncreasePool && this._debounceIncreasePool.flush();
349349
this.dataProvider(params, (items, size) => {
350350
if (size !== undefined) {
351351
cache.size = size;

test/data-provider.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366
// Effective size should change in between the data requests
367367
expect(renderSpy.called).to.be.true;
368368
expect(increasePoolSpy.callCount).to.above(1);
369-
expect(updateItemSpy.callCount).to.be.below(90);
369+
expect(updateItemSpy.callCount).to.be.below(180);
370370
});
371371

372372
it('should keep item expanded on itemIdPath change', () => {

test/scroll-to-index.html

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
</template>
4040
</test-fixture>
4141

42+
<test-fixture id="treeGrid">
43+
<template>
44+
<vaadin-grid style="width: 200px; height: 500px;">
45+
<vaadin-grid-tree-column path="name" header="foo" item-has-children-path="hasChildren"></vaadin-grid-tree-column>
46+
</vaadin-grid>
47+
</template>
48+
</test-fixture>
4249
<script>
4350
describe('Scroll to index', () => {
4451

@@ -228,8 +235,39 @@
228235
});
229236

230237
});
231-
</script>
238+
describe('Tree grid', () => {
239+
240+
// Issue https://github.com/vaadin/vaadin-grid/issues/2107
241+
it('should display correctly when scrolled to bottom immediately after setting dataProvider', done => {
242+
const grid = fixture('treeGrid');
243+
grid.size = 1;
244+
const numberOfChidren = 250;
245+
grid.itemIdPath = 'name';
246+
const PARENT = {name: 'PARENT', hasChildren: true};
247+
grid.dataProvider = ({page, parentItem}, cb) => {
248+
setTimeout(() => {
249+
if (!parentItem) {
250+
cb([PARENT], 1);
251+
return;
252+
}
232253

254+
const scope = parentItem.name;
255+
const offset = page * grid.pageSize;
256+
cb([...new Array(grid.pageSize)].map((_, index) => {
257+
return {name: 'Child ' + (offset + index), hasChildren: false};
258+
}), numberOfChidren);
259+
if (page > 0) {
260+
expect(grid._physicalCount).to.be.above(10);
261+
done();
262+
}
263+
});
264+
};
265+
grid.expandedItems = [PARENT];
266+
grid.scrollToIndex(250);
267+
});
268+
269+
});
270+
</script>
233271
</body>
234272

235273
</html>

0 commit comments

Comments
 (0)