Skip to content

Redundant write callback invocations for no-op property changes #23983

@Legioth

Description

@Legioth

Description of the bug

If an element has a two-way signal binding for an property, then every invocation of Element.setProperty triggers running the write callback again even if the provided value is the same as the previous value. This is inconsistent with other element property features such as addPropertyChangeListener where assigning the same value again is completely ignored.

Expected behavior

Expected that the write callback is called only if the property value changes.

Minimal reproducible example

ValueSignal<String> signal = new ValueSignal<>("Value");

Element bindingElement = new Element("input");
bindingElement.bindProperty("value", signal, value -> {
    System.out.println("Writback callback: " + value);
    signal.set(value);
});
Element listenerElement = new Element("input");
listenerElement.addPropertyChangeListener("value", event -> {
    System.out.println("Property change: " + event.getValue());
});
getElement().appendChild(bindingElement);
getElement().appendChild(listenerElement);

add(new Button("Reset field", click -> {
    bindingElement.setProperty("value", "Reset");
    listenerElement.setProperty("value", "Reset");
}));
  1. Click the button, observe that each listener is run
  2. Click the button again, observe that the listener isn't run but the write callback is run

Versions

  • Vaadin / Flow version: Vaadin 25.1.0-rc2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions