webcomponents / polyfills

Web Components Polyfills
BSD 3-Clause "New" or "Revised" License
1.14k stars 165 forks source link

isSameNode exception with shadowRoot #436

Open matthias-ccri opened 3 years ago

matthias-ccri commented 3 years ago

Description

Error thrown when passing a custom element's shadowRoot to Node.isSameNode (FF 60, Chrome 46). While the current DOM spec doesn't mandate throwing an error when a non-Node is passed to isSameNode, these browser versions do throw. And it looks like the wc polyfills are creating a synthetic shadowRoot object that is not an instance of Node.

I came across this issue when using the @spectrum-web-components/tooltip package, but I isolated it down to the root cause.

I'm logging this issue because I couldn't find any record of the issue online. Please advise if these browser versions are outside of the supported browser range. The readme is a little unclear about what the compatibility matrix includes, and the "current versions" statement is relative to the time it was written, which I don't know.

Thanks

Example

https://output.jsbin.com/nedafux

Steps to reproduce

  1. Create my-element
  2. In the constructor, create a shadow root (open).
  3. Call document.body.isSameNode(this.shadowRoot)
  4. Append my-element to document.body
  5. Load the page with Firefox 60 or Chromium 46
  6. See the error in the console.

Expected behavior

There should be no error thrown.

Actual behavior

Error is thrown: Firefox 60: TypeError: Argument 1 of Node.isSameNode does not implement interface Node. Chromium 46: TypeError: Failed to execute 'isSameNode' on 'Node': parameter 1 is not of type 'Node'

Version

@webcomponents/webcomponentsjs@2.5.0

Browsers affected

Note: the issue no longer appears in at least Firefox 68 and Chrome 57.

matthias-ccri commented 3 years ago

Has anyone seen this?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.