Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

bugfix: fixes and optimizes everything regarding event debouncing :-) #17410

Merged
merged 15 commits into from
Aug 22, 2023

Conversation

mstahv
Copy link
Member

@mstahv mstahv commented Aug 9, 2023

Description

The event order when using debouncing sends events in wrong order. This was tried to be fixed in #14035 but apparently only issues with the core TextField was fixed (or then this was again regressed in the regression fix #15615) 🤷‍♂️

Using this trivial Element API usage like below, type in for example asdfg to the input field -> g-event fires before k-event and there are multiple server visits (there should be just one).

    Element el = new Element("input");
    el.executeJs("""
            const el = this;
            var id = 0;
            this.addEventListener('keydown', function(event) {
                id++;
                const ke = new Event("k-event");
                ke.id = id;
                el.dispatchEvent(ke);
            
                if(event.key == 'g') {
                    const ge = new Event("g-event");
                    ge.id = id;
                    el.dispatchEvent(ge);
                }
            });
    """);
    DomListenerRegistration keyreg = el.addEventListener("k-event", e -> {
        System.out.println(LocalTime.now() + " k-event" + e.getEventData().getNumber("event.id") + " phase: " + e.getPhase());
    });
    keyreg.addEventData("event.id");
    keyreg.debounce(3000);

    // Note, with multiple debounce phases, things get really weird...

    // I'm interested of g-event eagerly, so I don't debounce it
    // BUT, AFAIK, key-event should ALWAYS come in before!!
    // But it is not... :(
    DomListenerRegistration greg = el.addEventListener("g-event", e -> {
        System.out.println(LocalTime.now() + " g-event " + e.getEventData().getNumber("event.id"));
    });
    greg.addEventData("event.id");

    getElement().appendChild(el);

While investigating the this issue there was also a dozen of other related isseus, incomplete docs and missing integration test.

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/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.

@sonatype-lift
Copy link

sonatype-lift bot commented Aug 9, 2023

Sonatype Lift is retiring

Sonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console.
We are extremely grateful and thank you for your support over the years.

📖 Read about the impacts and timeline

@github-actions
Copy link

github-actions bot commented Aug 9, 2023

Test Results

1 001 files  ±0  1 001 suites  ±0   58m 50s ⏱️ - 6m 13s
6 389 tests ±0  6 348 ✔️ ±0  41 💤 ±0  0 ±0 
6 642 runs   - 4  6 594 ✔️  - 4  48 💤 ±0  0 ±0 

Results for commit c0a8745. ± Comparison against base commit a49a588.

♻️ This comment has been updated with latest results.

@vaadin-bot vaadin-bot added +1.0.0 and removed +0.0.1 labels Aug 10, 2023
old component test was fine in CI, but flaky on my workstation, increased debounce timeout to make it more stable
Copy link
Collaborator

@mcollovati mcollovati left a comment

Choose a reason for hiding this comment

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

Just some typos

@mcollovati
Copy link
Collaborator

The overall change looks good, and the tests are more reliable.
However, since the change involves a behavior change (), we need to:

Note that now the client side seems to throw an exception with "leading only"
mstahv and others added 7 commits August 11, 2023 16:43
…est/ui/DomEventFilterIT.java

Co-authored-by: Marco Collovati <marco@vaadin.com>
…est/ui/DomEventFilterIT.java

Co-authored-by: Marco Collovati <marco@vaadin.com>
…est/ui/DomEventFilterIT.java

Co-authored-by: Marco Collovati <marco@vaadin.com>
Good old console logging...

SimpleElementBinderStrategy depended on the implicit leading phase, and
caused exceptions to console with only leading event. Didn't harm the functionality
but better this way :-)
I don't like this, especially without any real use case, but this way thould be ok to land in x.x.1 release as the behaviour don't change (except dropping some invalid events and extra requests).

 * configuration with all phases now works at least in trivial cases
 * improved docs
 * refactored names to make the code a tiny bit readable
@mstahv mstahv marked this pull request as draft August 11, 2023 18:19
@mstahv
Copy link
Member Author

mstahv commented Aug 11, 2023

Converted back to draft. After the latest changes, obsolete requests are back or my manual test fails somehow 👎

@mstahv mstahv marked this pull request as ready for review August 11, 2023 19:05
@mstahv
Copy link
Member Author

mstahv commented Aug 11, 2023

Nope, it is fine, "just" other slightly related issues (#17430, #17429) causing obsolete server visit.

@mshabarov mshabarov self-requested a review August 14, 2023 11:05
@mstahv
Copy link
Member Author

mstahv commented Aug 14, 2023

Checked the reference docs. Nothing urgent needs to change there. Of course more hands on examples of everything would be nice. And maybe mentioning that combining all modes is weird and may cause double calls for the same event 🤷‍♂️

@vaadin-bot vaadin-bot removed the +1.0.0 label Aug 21, 2023
@mshabarov
Copy link
Contributor

mshabarov commented Aug 22, 2023

@mstahv With this patch I see the same behaviour as previously without it: "g" event is triggered on the server first, and "k" goes after it:

14:34:24.148306 g-event 5.0
14:34:27.798952 k-event6.0 phase: TRAILING

How did you test it?

@mstahv
Copy link
Member Author

mstahv commented Aug 22, 2023

Regression in the branch 🤔 Make sure you are not causing another keydown (like shortcut to change focus to IDE) event if you are using the original case in the issue description. I tested the original case with a separate project, but then the changed the implementation still while making the IT test suit more complete 🤷‍♂️ But it still don't seem to contain test with two different event types.

Would have been easier to check two weeks ago 😤

@mstahv
Copy link
Member Author

mstahv commented Aug 22, 2023

Added case to DomEventFilterIT/View locally testing with Safari all seems to work fine, but can't these days be sure as the front-end bundle things are rather complex 🤓

@vaadin-bot vaadin-bot added +1.0.0 and removed +0.0.1 labels Aug 22, 2023
@sonarcloud
Copy link

sonarcloud bot commented Aug 22, 2023

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 12 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@mshabarov
Copy link
Contributor

The same behaviour was observed because of pre-compiled dev bundle was used, which did not contain these changes. With forcing the frontend build, these changes are now shown and seems to work as expected: one request to server is sent and events go in order.
Let's apply this patch and check Flow Components tests later.
I propose to include this only to 24.2 until enough time passes by, then we can pick it to other branches.

@mshabarov mshabarov dismissed mcollovati’s stale review August 22, 2023 14:06

Marco is on vacation and seems his comments have been addressed.

@mshabarov mshabarov merged commit 349945a into main Aug 22, 2023
26 checks passed
@mshabarov mshabarov deleted the bugfix/throttling-and-friends branch August 22, 2023 14:09
@vaadin-bot
Copy link
Collaborator

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

vaadin-bot pushed a commit that referenced this pull request Aug 30, 2023
The event order when using debouncing sends events in wrong order. This was tried to be fixed in #14035 but apparently only issues with the core TextField was fixed (or then this was again regressed in the regression fix #15615) 

---------

Co-authored-by: Marco Collovati <marco@vaadin.com>
Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
vaadin-bot added a commit that referenced this pull request Aug 30, 2023
… (#17516)

The event order when using debouncing sends events in wrong order. This was tried to be fixed in #14035 but apparently only issues with the core TextField was fixed (or then this was again regressed in the regression fix #15615) 

---------

Co-authored-by: Matti Tahvonen <matti@vaadin.com>
Co-authored-by: Marco Collovati <marco@vaadin.com>
Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
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: property synchronization events cause a value flush
4 participants