Skip to content

Commit

Permalink
Revert "its not clear that we need this."
Browse files Browse the repository at this point in the history
This reverts commit af83ed4.
  • Loading branch information
botandrose-machine committed Jan 14, 2025
1 parent 80826c4 commit d0a2414
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/idiomorph.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,13 @@ var Idiomorph = (function () {
function moveBefore(parentNode, element, after) {
// @ts-ignore - use proposed moveBefore feature
if (parentNode.moveBefore) {
// @ts-ignore - use proposed moveBefore feature
parentNode.moveBefore(element, after);
try {
// @ts-ignore - use proposed moveBefore feature
parentNode.moveBefore(element, after);
} catch (e) {
// fall back to insertBefore as some browsers may fail on moveBefore when trying to move Dom disconnected nodes to pantry
parentNode.insertBefore(element, after);
}
} else {
parentNode.insertBefore(element, after);
}
Expand Down
25 changes: 25 additions & 0 deletions test/retain-hidden-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,31 @@ describe("Hidden state preservation tests", function () {
states.should.eql([true]);
});

it("moveBefore function fails back to insertBefore if moveBefore fails", function () {
getWorkArea().append(
make(`
<div>
<input type="checkbox" id="first">
<input type="checkbox" id="second">
</div>
`),
);
// replace moveBefore function with a boolean which will fail the try catch
document.getElementById("first").parentNode.moveBefore = true;

let finalSrc = `
<div>
<input type="checkbox" id="second">
<input type="checkbox" id="first">
</div>
`;
Idiomorph.morph(getWorkArea(), finalSrc, {
morphStyle: "innerHTML",
});

getWorkArea().innerHTML.should.equal(finalSrc);
});

it("moveBefore function falls back to insertBefore if moveBefore is missing", function () {
getWorkArea().append(
make(`
Expand Down

0 comments on commit d0a2414

Please sign in to comment.