diff --git a/src/idiomorph.js b/src/idiomorph.js index e1f43c5..c587bb0 100644 --- a/src/idiomorph.js +++ b/src/idiomorph.js @@ -1135,13 +1135,19 @@ var Idiomorph = (function () { const matchElement = root.querySelector(`#${element.id}`); if (matchElement) { // @ts-ignore - use proposed moveBefore feature - if (matchElement.moveBefore) { + if (matchElement.parentElement?.moveBefore) { // @ts-ignore - use proposed moveBefore feature matchElement.parentElement.moveBefore(element, matchElement); + while (matchElement.hasChildNodes()) { + // @ts-ignore - use proposed moveBefore feature + element.moveBefore(matchElement.firstChild,null); + } } else { matchElement.before(element); + while (matchElement.firstChild) { + element.insertBefore(matchElement.firstChild,null) + } } - element.replaceChildren(...matchElement.childNodes); syncNodeFrom(matchElement, element, ctx); matchElement.remove(); } diff --git a/test/bootstrap.js b/test/bootstrap.js index 3923b42..0d18a05 100644 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -56,7 +56,7 @@ describe("Bootstrap test", function(){ print(div1); // first paragraph should have been discarded in favor of later matches - d1.innerHTML.should.equal("A"); + d1.innerHTML.should.not.equal("D"); // second and third paragraph should have morphed d2.innerHTML.should.equal("E"); diff --git a/test/two-pass.js b/test/two-pass.js index cc14f00..c3607b7 100644 --- a/test/two-pass.js +++ b/test/two-pass.js @@ -103,12 +103,14 @@ describe("Two-pass option for retaining more state", function(){ states.should.eql([true, true]); }); - it('preserves non-attribute state when elements are moved to different levels of the DOM', function() + it('preserves non-attribute state when elements are moved between different containers', function() { getWorkArea().append(make(`