vaadin / flow-components

Java counterpart of Vaadin Web Components
100 stars 66 forks source link

ev.isFromClient() returns true in RTE #1894

Open mlopezFC opened 3 years ago

mlopezFC commented 3 years ago

Description

In a value change listener, the property fromClient in the event will return true when the modification is being made by the server side.

Expected outcome

The property fromClient should return false, given that the change was originated from the server side.

Actual outcome

The property will return true

Minimal reproducible example

This example shows that a TextField will return the opposite under the same conditions:

@Route
@PWA(name = "My Application", shortName = "My Application")
public class MainView extends VerticalLayout {
    public MainView() {
        RichTextEditor rte = new RichTextEditor();
        rte.setValueChangeMode(ValueChangeMode.EAGER);
        rte.addValueChangeListener(ev -> System.out.println("RTE From client: " + ev.isFromClient()));
        add(rte);

        TextField tf = new TextField();
        tf.addValueChangeListener(ev -> System.out.println("TF From client: " + ev.isFromClient()));
        add(tf);

        Button button1 = new Button("Test", event -> {
            rte.asHtml().setValue("<p>Test</p>");
        });
        Button button2 = new Button("Test", event -> {
            tf.setValue("Test");
        });
        add(button1,button2);
    }
}

Steps to reproduce

Clear steps describing how to reproduce the issue.

  1. Add a RTE to the page
  2. Add a value change listener and inspect the property from client inside it
  3. Add a button that when pressed will trigger a change using rte.asHtml().setValue()

Environment

Browsers Affected

knoobie commented 3 years ago

See e.g. https://github.com/vaadin/flow/issues/9768 for more information. It's possible that such a round-trip is done here as well.

mlindfors commented 4 months ago

With Vaadin 24.3.9 the example snippet is now returning false in both cases.

If, however, you go and change the rte.asHtml().setValue("<p>Test</p>");to rte.asHtml().setValue("Test");, you get two value change events, where the second one is reportedly coming from the client. Of course you shouldn't be pushing broken values into the thing to begin with, so I don't know how big of an issue this actually is.