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

Validation is triggered more frequently than necessary #4390

Closed
vursen opened this issue Dec 16, 2022 · 5 comments
Closed

Validation is triggered more frequently than necessary #4390

vursen opened this issue Dec 16, 2022 · 5 comments

Comments

@vursen
Copy link
Contributor

vursen commented Dec 16, 2022

Description

Reported at #1158 (comment)

Improving validation in the scope of vaadin/platform#3066 has resulted in some performance degradation, that is, server-side validation can be triggered now more often than before. This especially hurts in cases where Binder validators make database requests.

The culprit is the validated event that is fired by the web component and that the server listens to nowadays. This event can be triggered in response to certain actions coming from the server, such as setting a new value. This, in turn, can lead to triggering a new round of server-side validation, even if the server has already validated that value during a prior round-trip.

To illustrate the problem, consider what happens when calling binder.setBean():

1st round-trip:

  1. Binder updates the component's value.
  2. Binder runs validation.
  3. The server sends the value to the client-side.

2nd round-trip:

  1. The web component runs validation for the new value which fires a validated event in the end.
  2. The validated event causes a new round-trip.
  3. The server runs validation again.

Expected outcome

The server should not revalidate values that have been already validated before.

Environment

Vaadin version(s): v24
OS: Mac OS

@cdir
Copy link

cdir commented Mar 13, 2023

I think this is more than a performance problem. In my case the client-side validation overrules a server-side validation.

Here is a simple example:

   TextField field1 = new TextField();
   TextField field2 = new TextField();
   field1.addValueChangeListener(e -> {
        field1.setInvalid(true);
        field1.setErrorMessage("error");
        field2.setInvalid(true);
        field2.setErrorMessage("error");
   });
   add(field1);
   add(field2);

When you enter something in field1, a validation message should appear. But the client,side validation overwrites the invalid flag immediately.

In my real case, there is some business logic that sets an error message and the invalid flag when the input value is not valid.

With Vaadin 24, the feature flag is still present but ignored and the client-side validation is always enabled. Therefore, all server-side validation is overridden.

@vursen vursen changed the title Validation is triggered more often than necessary Validation is triggered more frequently than necessary Jun 21, 2023
@simasch
Copy link

simasch commented Aug 2, 2023

This isn't very pleasant because this prevents me from migrating to Vaadin 24!

@yuriy-fix
Copy link
Contributor

We are currently refactoring the validation logic of triggering the validation from the client side. The aim is to reduce the number of roundtrips and validation invocations.

@vursen
Copy link
Contributor Author

vursen commented Nov 6, 2023

The issue will be resolved as part of #5537.

@yuriy-fix
Copy link
Contributor

The issue is resolved as a part of #5537. Fix is available in 24.3.0-beta1.
DateTimePicker behaviour will be tackled separately.

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

No branches or pull requests

4 participants