From 41f870912bdd872e3376b090e863641928568a24 Mon Sep 17 00:00:00 2001 From: web-padawan Date: Wed, 20 Feb 2019 11:42:10 +0200 Subject: [PATCH] refactor: defer scroll position adjustment until rAF --- src/vaadin-combo-box-mixin.html | 6 +++++- test/.eslintrc.json | 1 + test/common.js | 12 ++++++++++++ test/filtering.html | 8 +++++--- test/keyboard.html | 2 +- test/scrolling.html | 4 ++-- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/vaadin-combo-box-mixin.html b/src/vaadin-combo-box-mixin.html index 4c1c10a39..23b587f4d 100644 --- a/src/vaadin-combo-box-mixin.html +++ b/src/vaadin-combo-box-mixin.html @@ -548,8 +548,12 @@ // Ensure metrics are up-to-date this.$.overlay.updateViewportBoundaries(); - Polymer.Async.microTask.run(() => this.$.overlay.adjustScrollPosition()); + // Force iron-list to create reusable nodes. Otherwise it will only start + // doing that in scroll listener, which is especially slow in Edge. + this.$.overlay._selector._increasePoolIfNeeded(); setTimeout(() => this._resizeDropdown(), 1); + // Defer scroll position adjustment to prevent freeze in Edge + window.requestAnimationFrame(() => this.$.overlay.adjustScrollPosition()); // _detectAndDispatchChange() should not consider value changes done before opening diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 742455906..cff17d3a1 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -22,6 +22,7 @@ "fire": false, "fireMousedownMouseupClick": false, "getCustomPropertyValue": false, + "onceScrolled": false, "System": false, "HTMLImports": false, "MockInteractions": false, diff --git a/test/common.js b/test/common.js index 151c5b0e4..e008a1782 100644 --- a/test/common.js +++ b/test/common.js @@ -34,6 +34,18 @@ var fireMousedownMouseupClick = (node) => { fire('click', node); }; +var onceScrolled = (scroller) => { + return new Promise(resolve => { + const listener = () => { + scroller.removeEventListener('scroll', listener); + setTimeout(() => { + resolve(); + }); + }; + scroller.addEventListener('scroll', listener); + }); +}; + var describeSkipIf = (bool, title, callback) => { bool = typeof bool == 'function' ? bool() : bool; if (bool) { diff --git a/test/filtering.html b/test/filtering.html index e3b9e7479..4436ff2c2 100644 --- a/test/filtering.html +++ b/test/filtering.html @@ -125,9 +125,11 @@ setInputValue('b'); // first scroll after open is async - setTimeout(() => { - expect(spy.callCount).to.eql(1); // scrolls once on open - done(); + window.requestAnimationFrame(() => { + setTimeout(() => { + expect(spy.callCount).to.eql(1); // scrolls once on open + done(); + }, 1); }); }); diff --git a/test/keyboard.html b/test/keyboard.html index e82351e59..87d2d1cf3 100644 --- a/test/keyboard.html +++ b/test/keyboard.html @@ -530,7 +530,7 @@ comboBox.open(); - setTimeout(() => { + onceScrolled(comboBox.$.overlay._scroller).then(() => { expect(selector.firstVisibleIndex).to.be.within(50 - comboBox.$.overlay._visibleItemsCount(), 50); done(); }); diff --git a/test/scrolling.html b/test/scrolling.html index ae44afde7..82bc0ec58 100644 --- a/test/scrolling.html +++ b/test/scrolling.html @@ -85,10 +85,10 @@ combobox.value = combobox.items[50]; combobox.open(); - setTimeout(() => { + onceScrolled(combobox.$.overlay._scroller).then(() => { expectSelectedItemPositionToBeVisible(); done(); - }, 1); + }); }); it('should make selected item visible after reopen', done => {