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

Terminal.open: support WebComponent when checking DOM Node #3239

Merged
merged 1 commit into from
Feb 1, 2021
Merged

Terminal.open: support WebComponent when checking DOM Node #3239

merged 1 commit into from
Feb 1, 2021

Conversation

sangxxh
Copy link
Contributor

@sangxxh sangxxh commented Jan 31, 2021

Close #2642

First contribution.

I've replicated the issue and debugged.

Debug

  • Before:

    before

  • After:

    after

Replicate Issue

In demo/client.ts, find the if (document.location.pathname === "/test") block and put the code inside the DEBUG START/END comment blocks below into it. Go to http://localhost:3000/test to check.

if (document.location.pathname === "/test") {
  window.Terminal = Terminal;
  window.AttachAddon = AttachAddon;
  window.FitAddon = FitAddon;
  window.SearchAddon = SearchAddon;
  window.SerializeAddon = SerializeAddon;
  window.Unicode11Addon = Unicode11Addon;
  window.WebLinksAddon = WebLinksAddon;
  window.WebglAddon = WebglAddon;

  // ====================
  // DEBUG start
  // ====================

  class DemoWebComponent extends HTMLDivElement {
    constructor() {
      super();

      this.attachShadow({ mode: "open" });
    }
  }

  window.customElements.define("demo-webcomponent", DemoWebComponent, { extends: "div" });

  const appContainer = document.createElement("demo-webcomponent");
  terminalContainer.appendChild(appContainer);

  const shadowRoot = appContainer.attachShadow({ mode: "open" });

  const xtermContainer = document.createElement("div");
  xtermContainer.id = "xterm-container";
  shadowRoot.appendChild(xtermContainer);

  console.group("debug");
  console.log(xtermContainer.isConnected); // true
  console.log(document.body.contains(xtermContainer)); // false
  console.groupEnd();

  const term = new Terminal();
  // log to browser console
  term.setOption("logLevel", "debug");
  window.term = term;

  term.open(xtermContainer);
  term.write("Hello xTerm");

  // ====================
  // DEBUG END
  // ====================
}

@Tyriar Tyriar added this to the 4.11.0 milestone Feb 1, 2021
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the thorough testing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check if element is attached to DOM is too specific
2 participants