TricomB2B / object-fit-videos

Polyfill for object-fit and object-position CSS properties on video elements. Works with IE9-11, Edge, Safari <10.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in IE11: Failed to execute 'appendChild' on 'Node': The new child element contains the parent.

smohadjer opened this issue · comments

When I use this polyfill with webcomponents/polyfill I see the following error in IE11 console:

SCRIPT5022: Failed to execute 'appendChild' on 'Node': The new child element contains the parent.

It seems the error is caused by following snippet in object-fit-videos.js:

 // create and insert a wrapper element
    var $wrap = document.createElement('object-fit');
    $wrap.appendChild($el.parentNode.replaceChild($wrap, $el));

Honestly I can't make sense of this snippet either. If the purpose is to wrap the video element inside an 'object-fit' element (no idea why using custom element here, but that's another story), why are we replacing $el with $wrap before appending $el in $wrap? If I refactor this code as I have displayed below the error is not thrown anymore and object-fit works again:

    // create and insert a wrapper element
    var $wrap = document.createElement('object-fit');
    $el.parentNode.insertBefore($wrap, $el);
    $wrap.appendChild($el);

I'm surprised that nobody has run into this!