Skip to content

Calling Dialog::removeAll destroys interaction with header and footer of a dialog #5263

Closed

Description

@knoobie

Description

Title says it all. Once Dialog::removeAllis called, any action e.g. Button click from a button within the dialog's header or footer is not reaching the server anymore.

Expected outcome

Dialog::removeAll should NOT interfere with the header and footer feature of the grid.

Minimal reproducible example

new Button("Open Dialog", e -> {
      AtomicReference<Dialog> reference = new AtomicReference<>();
      var dialog = new Dialog();
      reference.set(dialog);
      dialog.getFooter().add(new Button("Click me after clear", ex -> {
        System.out.println("Was I called? :(");
      }));
      dialog.add(new Button("Click me to clear dialog", event -> {
        reference.get().removeAll();
        reference.get().add(new Paragraph("I was cleared!"));
      }));
      dialog.open();
    })

Steps to reproduce

  1. Click "Open Dialog"
  2. Click "Click me to clear the dialog"
  3. Click "Click me after clear"
  4. Expectation: "Was I called? :(" in the log.
  5. Actual: No log

Environment

Vaadin version(s): 24.1

Browsers

Issue is not browser related

Activity

  1. changed the title [-]Calling `Dialog::removeAll` destroy interaction with header and footer of a dialog[/-] [+]Calling `Dialog::removeAll` destroys interaction with header and footer of a dialog[/+] on Jul 17, 2023
  2. knoobie commented on Jul 19, 2023

    @knoobie
    ContributorAuthor

    Workaround:

      @Override
      public void removeAll() {
        remove(getChildren().filter(component -> !component.getStyle().has("display")
            && !"contents".equals(component.getStyle().get("display")))
          .collect(Collectors.toList()));
      }
  3. rolfsmeds commented on Jul 19, 2023

    @rolfsmeds
    Contributor

    Agree, removeAll (and similar HasComponents methods) should only affect the content area, not elements in the title, header-content or footer slots.

    **Edit: ** This gets tricky as there are a lot of methods from various interfaces that act on the Dialog's child elements in general. Need to research the best approach here.

  4. rolfsmeds commented on Jul 19, 2023

    @rolfsmeds
    Contributor

    Should also check if ConfirmDialog is broken in a corresponding way.

  5. self-assigned this
    on Jul 19, 2023
  6. sissbruecker commented on Jul 19, 2023

    @sissbruecker
    Member

    This part looks suspicious:

    This adds the header / footer wrapper elements as a direct children of the dialog, which also means they will be removed there when calling removeAll. This also affects other APIs in the dialog such as getChildren, getChildCount and addComponentAtIndex.

    One thing to try would be to add the wrappers as virtual children instead.

  7. knoobie commented on Dec 2, 2025

    @knoobie
    ContributorAuthor

    How can the exact bug be re-introduced in V25? My example from above is broken again.. Luckily I've written a test to verify it.. :( @rolfsmeds

  8. knoobie commented on Dec 2, 2025

    @knoobie
    ContributorAuthor

    Funny thing - it's even more broken. In the past the footer/header was still visible - now the dialog is empty and broken

  9. knoobie commented on Dec 2, 2025

    @knoobie
    ContributorAuthor

    Workaround:

      @Override
      public void removeAll() {
        getElement().getChildren().forEach(child -> {
          if (!child.hasAttribute("slot")) {
            child.removeFromParent();
          }
        });
      }
  10. web-padawan commented on Dec 2, 2025

    @web-padawan
    Member

    @knoobie Could you please create a new issue for this problem? We are typically using new tickets for regressions.

  11. knoobie commented on Dec 2, 2025

    @knoobie
    ContributorAuthor

    Done: #8315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions