textField.addKeyDownListener sends request on every keypress?

I have a textField with a regular keyDown listener.
The event fires when it should, but browser sends a request on every keypress.
That doesn’t seem right.

@Route(value="/test")
public class Test extends VerticalLayout {

    public Test() {

    	var textField = new TextField("TextField");

    	textField.addKeyDownListener(Key.ESCAPE, event -> {
    		System.out.println("ESC:\n" + event.toString());
        });

        add(textField);

    }

}

Vaadin 24.5.0.beta5, Firefox 130.0.1, Windows 10

That is indeed how the listener is implemented, the key check happens on the server: flow/flow-server/src/main/java/com/vaadin/flow/component/KeyEventListener.java at 818d28490a7c74763987e9761b22d5b1071b1653 · vaadin/flow · GitHub

Doesn’t mean it is right though. :smile:
Seems like it should’ve been filtered both on the client-side and the server-side.

Not sure how to feel about this one. Vaadin is a chatty app anyway, so maybe I’m overthinking this, but it just feels wrong to generate pointless traffic.

I guess I’ll use the element-level filtered event handler instead.
That also seems wrong; using a low-level API when a high-level API is available, but in this case I think it is the least wrong.

Why do you think that this could cause issues? We have many key listeners and there is no problem with that.

As I said, maybe I’m overthinking this, but I just assume less traffic is better.

I have not observed any problems, other than me wasting time debugging why I got this unexpected traffic.

Yes. Sometimes so. That is why in TextField there are the value change modes, so that you can control it. But that applies only the value change event.