webcomponents / polyfills

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

[ShadyDOM] Node.prototype.replaceChild removes node when same ref_node is used #349

Open tmsns opened 4 years ago

tmsns commented 4 years ago

Description

When using Node.prototype.replaceChild with the same node as ref_node, the node gets cleaned. (eg. removed from its parent)

Example

https://jsbin.com/qajapuxupa/1/edit?html,console,output

Steps to reproduce

  1. Create a div and a span within
  2. Get a reference to both elements.
  3. Execute replaceChild on div, but use span for both the node as the ref_node
  4. The span element is not connected anymore.

Expected behavior

The span element is untouched. (check other browsers)

Actual behavior

The span element has been cleaned

Version

@webcomponents/webcomponentsjs@2.4.3

Browsers affected

tmsns commented 4 years ago

The issue resides here: https://github.com/webcomponents/polyfills/blob/master/packages/shadydom/src/patches/Node.js#L463 The two functions should only be executed if node and ref_node are different.

If you guys like, I can send in a MR? 😃

stale[bot] commented 3 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.

stale[bot] commented 12 months ago

This issue has been automatically closed after being marked stale. If you're still facing this problem with the above solution, please comment and we'll reopen!