vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
619 stars 167 forks source link

Client-side value not sent to server in certain cases #20442

Open tepi opened 5 days ago

tepi commented 5 days ago

Description of the bug

Pre-requirements: We need a field with a server-side value change handler that takes some time to execute (slow network or artificial sleep when testing) and at the end sets the field value to a pre-set value.

        Input input2 = new Input();
        input2.addValueChangeListener(e -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                throw new RuntimeException(ex);
            }
            input2.setValue("fromserver");
        });

Steps to reproduce the issue:

  1. Select the field, type in 1 and press enter -> value should be "fromserver".
  2. Type 1 at the end of the field and press enter. Then quickly type 2 at the end of the field while the thread is sleeping. Value should briefly be "fromserver12" and once the round-trip completes it should be reset to "fromserver".
  3. Now type 1 at the end of the field (value should be "fromserver1") and press enter -> nothing happens

Issue was found while fixing https://github.com/vaadin/flow/issues/20365 via https://github.com/vaadin/flow/pull/20431

Expected behavior

After pressing enter in step three above, the value "fromserver1" should be sent to the server but it is not.

Minimal reproducible example

Can be quite easily demonstrated with test code here https://github.com/vaadin/flow/pull/20431/files#diff-9c44f8ed3265aa1d33149204e10dacbcd207f8943114e161470c64f7509595d7

But note this happens on current main and on the above PR branch so the issue is not introduced by that PR.

Versions