Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: flush debouncer to fix timing issue with scroll to index (CP 6.0) #2170

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/vaadin-grid-data-provider-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ export const DataProviderMixin = (superClass) =>
if (this.__pendingScrollToIndex && this.$.items.children.length) {
const index = this.__pendingScrollToIndex;
delete this.__pendingScrollToIndex;

if (this._debounceIncreasePool) {
this._debounceIncreasePool.flush();
}

this.scrollToIndex(index);
}
}
Expand Down
35 changes: 34 additions & 1 deletion test/scroll-to-index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from '@esm-bundle/chai';
import { fixtureSync, nextFrame } from '@open-wc/testing-helpers';
import { flushGrid, infiniteDataProvider, listenOnce } from './helpers.js';
import '../vaadin-grid.js';
import '../vaadin-grid-tree-column.js';

const fixtures = {
small: `
Expand Down Expand Up @@ -209,9 +210,14 @@ describe('scroll to index', () => {
});
});
describe('Tree grid', () => {
let grid;

beforeEach(() => {
grid = fixtureSync(fixtures.treeGrid);
});

// 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';
Expand Down Expand Up @@ -239,5 +245,32 @@ describe('scroll to index', () => {
grid.expandedItems = [PARENT];
grid.scrollToIndex(250);
});

it('should not reuse rows if subitems are loaded while scrolling to bottom', (done) => {
grid.size = 25;

const parents = Array.from({ length: 10 }).map((_, i) => ({ name: i, hasChildren: true }));

grid.dataProvider = ({ parentItem }, cb) => {
setTimeout(() => {
if (!parentItem) {
cb(parents, parents.length);
} else {
const { name: parentName } = parentItem;
const children = Array.from({ length: 10 }).map((_, i) => ({
name: `${parentName * 10 + i}`,
hasChildren: false
}));
cb(children, children.length);

expect(grid._physicalCount).to.be.above(10);
done();
}
});
};

grid.expandedItems = [parents[parents.length - 1]];
grid.scrollToIndex(14);
});
});
});