Skip to content

fix: request pages asynchronously when scrolling - #4561

Merged
web-padawan merged 5 commits into
masterfrom
fix/combo-box/request-index-async
Sep 15, 2022
Merged

web-padawan merged 5 commits into
masterfrom
fix/combo-box/request-index-async

Conversation

@vursen

@vursen vursen commented Sep 9, 2022 •

Copy link
Copy Markdown
Contributor

Description

This PR makes combo-box-scroller request a page asynchronously when it encounters an item placeholder while scrolling. This is needed to prevent an immediate page request and therefore a possible infinite recursion in case the data provider implements page request cancelation logic by invoking data provider page callbacks with an empty array. This is exactly the case for the Flow counterpart that clears page callbacks by invoking them with an empty array to prevent too many page requests when scrolling fast. Without the current change, the scroller could immediately re-request the canceled page which led to looping since the Flow's data provider could in turn try to clear page callbacks again and so on.

  • Implementation
  • Unit tests

Fixes vaadin/flow-components#3553

Type of change

  • Bugfix

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@vursen
vursen force-pushed the fix/combo-box/request-index-async branch from c265b1e to 0afb763 Compare September 12, 2022 08:44
expect(dp.calledOnce).to.be.true;
});

it('should request pages asynchronously when scrolling', async () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: A new test.

@vursen vursen changed the title fix: request pages asynchronously when encountering placeholders fix: request pages asynchronously when scrolling Sep 12, 2022
@vursen
vursen marked this pull request as ready for review September 12, 2022 14:21

@web-padawan web-padawan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if the Flow counterpart tests pass with this change (haven't tried it locally).

It would be nice to also have the test emulating the actual logic of the connector (e.g. filling filteredItems with placeholder instances). Not a blocker though.

@vursen

vursen commented Sep 14, 2022 •

Copy link
Copy Markdown
Contributor Author

LGTM if the Flow counterpart tests pass with this change (haven't tried it locally).

I checked. There will be some failures but they all seem to be fixable by waiting for requestAnimationFrame after scrolling to an index:

 // vaadin-combo-box-flow-parent/vaadin-combo-box-flow-integration-tests/src/test/java/com/vaadin/flow/component/combobox/test/AbstractComboBoxIT.java

 protected void scrollToItem(ComboBoxElement comboBox, int index) {
   comboBox.openPopup();
   executeScript("arguments[0]._scroller.scrollIntoView(arguments[1])",
           comboBox, index);
+  // Wait for the data provider to pick up on pages that need
+  // to be loaded after scrolling.
+  getCommandExecutor().getDriver().executeAsyncScript(
+      "var callback = arguments[arguments.length - 1];"
+              + "requestAnimationFrame(callback)");
 }

It would be nice to also have the test emulating the actual logic of the connector (e.g. filling filteredItems with placeholder instances)

I was also thinking about that, but since we are planning to move that connector's logic into the web-components repo (#4568) in some form, I think we can add all the relevant tests then.

@vursen
vursen force-pushed the fix/combo-box/request-index-async branch from 9103f3a to 344d692 Compare September 14, 2022 16:17
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan
web-padawan merged commit 852023d into master Sep 15, 2022
@web-padawan
web-padawan deleted the fix/combo-box/request-index-async branch September 15, 2022 06:56
@vaadin-bot

Copy link
Copy Markdown
Collaborator

Hi @vursen , this commit cannot be picked to 23.2 by this bot, can you take a look and pick it manually?
Error Message: Error: Command failed: git cherry-pick 852023d
error: could not apply 852023d... fix: request pages asynchronously when scrolling (#4561)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

@vaadin-bot

Copy link
Copy Markdown
Collaborator

Hi @vursen , this commit cannot be picked to 23.1 by this bot, can you take a look and pick it manually?
Error Message: Error: Command failed: git cherry-pick 852023d
error: could not apply 852023d... fix: request pages asynchronously when scrolling (#4561)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

web-padawan pushed a commit that referenced this pull request Sep 15, 2022
* refactor: do not return index from __requestItemByIndex (#4551)

* fix: request pages asynchronously when scrolling (#4561)
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 23.3.0.alpha1 and is also targeting the upcoming stable 23.3.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: Lock screen when using combobox

4 participants