flow: Synchronized property unexpectedly reverts to last synchronized state

Description of the bug

Flow reverts the property’s value to the last synchronized state if the property changes again while the previous update is scheduled or is still being processed on the server. This behavior has blocked progress on DatePicker fallback parser feature.

https://github.com/user-attachments/assets/7ab2dd8b-6a47-48b5-8fee-8bbd5d0aa859

Expected behavior

I’d expect Flow to keep the new value and wait for the next synchronization event to send it to the server.

Minimal reproducible example

// frontend/my-field/my-field.ts

import { html, LitElement } from 'lit';
import { customElement, query } from 'lit/decorators.js';

@customElement("my-field")
class MyField extends LitElement {
  @query('input')
  inputElement!: HTMLInputElement;

  get inputElementValue() {
    return this.inputElement.value;
  }

  set inputElementValue(value) {
    console.warn('set inputElementValue', value);
    this.inputElement.value = value;
  }

  onChange() {
    this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }));
    this.inputElementValue = 'foobar'; // <------ Change the property right after the synchronization event
  }

  render() {
    return html`<input @change="${this.onChange}" />`
  }
}
@Tag("my-field")
@JsModule("my-field/my-field.ts")
public class MyField extends Component {
    @Synchronize(property = "inputElementValue", value = { "change" })
    public String getInputElementValue() {
        return getElement().getProperty("inputElementValue", "");
    }
}
@Route("my-field")
public class MyFieldView extends Div {
    public MyFieldView() {
        MyField myField = new MyField();
        add(myField);
    }
}

Versions

  • Vaadin / Flow version: 24.5 and possibly earlier
  • Java version: 17
  • OS version: Mac OS

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (13 by maintainers)

Commits related to this issue

Most upvoted comments

I’ll keep working on a fix. Is it enough to test with https://github.com/vaadin/flow-components/pull/6743 or do I need a custom version of web-components as well?

Thank you. Yes, that’s enough. This feature affects only the Flow component. Here is the test that reproduces the issue: enterParsableValue_enterShortcutValue

The second showcase gives a better presentation of the issues. It’s looks now end-user affecting especially with the slow internet. I’m leaning towards this is the bug in Flow, no matter what the solution would be. As a end-user, I don’t want my new value of the component to be overridden by the previous one.

This also opens another can of worms since arbitrary business logic can do whatever kind of processing for the input value on server side and send it back in the response. I guess in such case server-sent value should still override whatever was input by the user after the round-trip started?

@vursen Could you try your case(s) using https://github.com/vaadin/flow/tree/fix/flush-logic? Locally tested seems to fix the slow network case and did not break any flow-client tests.

Edit: some shortcut key test is failing but everything else is passing