vaadin / flow-components

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

Appending footer rows during attach causes event handlers to fire multiple times #1267

Open eriklumme opened 5 years ago

eriklumme commented 5 years ago

In a Grid with a TemplateRenderer that has an event handler, the event handler is fired multiple times on each event, if more than one footer row is appended during the grid's attach event.

Complete example

@Route("footer")
public class FooterRowTest extends Div {

    public FooterRowTest() {
        Grid<String> grid = new Grid<>();
        grid.addColumn(
                TemplateRenderer.<String>of("<span on-click=foo>Click me</span>")
                        .withEventHandler("foo",
                                item -> Notification.show(item, 3000, Notification.Position.TOP_CENTER)));
        grid.setItems("Test");
        add(grid);

        grid.addAttachListener(e -> {
            grid.appendFooterRow();
            grid.appendFooterRow();
        });
    }
}

Steps to reproduce

In the example, click the only item in the grid.

Expected outcome

One notification is shown

Actual outcome

Two notifications are shown

Versions

Platform 13.0.2, Chrome 73

eriklumme commented 5 years ago

Adding just one footer row does not seem to have an affect, likely because the first call reuses an existing column layer.

I have not been able to reproduce this by adding footer rows before or after the attach event.