Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving the component to another parent in one request cycle breaks the client side #46

Open
stefanuebe opened this issue May 31, 2022 · 2 comments
Labels
bug Something isn't working has workaround

Comments

@stefanuebe
Copy link

Simple scenario: the xterm console is shown in an draggable container. That draggable container is moved to another position, which is internally just a remove from parent A and attach to parent B. This results in an "empty" tag on the client side (it looses basically its xterm instance as it seems).

Removing and adding in two request cycles works, also simply hiding and showing it using setVisible.

The following example shows the issue in a simplified manner:

    public XTermView() {
        XTerm xterm = new XTerm();
        xterm.writeln("Hello world.\n\n");
        xterm.setWidth("500px");
        xterm.setHeight("250px");

        VerticalLayout left = new VerticalLayout(xterm);
        VerticalLayout right = new VerticalLayout();

        add(new Button("Switch", event -> {
            Component parent = xterm.getParent().orElse(null);
            if (parent == left) {
                right.add(xterm);
            } else {
                left.add(xterm);
            }
        }));


        SplitLayout layout = new SplitLayout(left, right);
        layout.setSplitterPosition(50);
        layout.setOrientation(SplitLayout.Orientation.HORIZONTAL);
        add(layout);
    }

The resulting element looks like this after using the Switch button:

image

@stefanuebe stefanuebe changed the title Moving the component to another parent in on cycle breaks the client side Moving the component to another parent in one request cycle breaks the client side May 31, 2022
@javier-godoy javier-godoy added the bug Something isn't working label May 31, 2022
@javier-godoy javier-godoy self-assigned this May 31, 2022
@javier-godoy
Copy link
Member

The terminal is instatiated in the constructor, initialized on _slotchange and disposed in disconnectedCallback, which is wrong and fails in that scenario. Calling remove and add in different cycles works, because the constructor is invoked before adding the component (although the state is lost, see #14 )

@javier-godoy
Copy link
Member

As a workaround, a two-phase switch can be initiated with executeJs/then:

 add(new Button("Two phase switch", event -> {
      Component parent = xterm.getParent().orElse(null);
      if (parent == left) {
          xterm.getElement().removeFromParent();
          getElement().executeJs("return").then(later->right.add(xterm));
      } else {
        xterm.getElement().removeFromParent();
        getElement().executeJs("return").then(later->left.add(xterm));
      }
  }));

@javier-godoy javier-godoy removed their assignment Oct 20, 2022
@paodb paodb moved this to Under consideration in Flowing Code Addons May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has workaround
Projects
Status: Under consideration
Development

No branches or pull requests

2 participants