Skip to content

Commit

Permalink
fix bug in isIdSetMatch being subtly looser than softMatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
botandrose-machine committed Jan 15, 2025
1 parent 560d3d3 commit b5b6560
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/idiomorph.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,9 @@ var Idiomorph = (function () {
* @returns {boolean}
*/
function isIdSetMatch(oldNode, newNode, ctx) {
if (
oldNode instanceof Element &&
newNode instanceof Element &&
oldNode.tagName === newNode.tagName
) {
if (oldNode.id !== "" && oldNode.id === newNode.id) {
return true;
} else {
return getIdIntersectionCount(oldNode, newNode, ctx) > 0;
}
}
return false;
return oldNode instanceof Element &&
isSoftMatch(oldNode, newNode) &&
getIdIntersectionCount(oldNode, newNode, ctx) > 0;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/fidelity.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ describe("Tests to ensure that idiomorph merges properly", function () {
testFidelity("<main></main>", "<main><p>hello you</p></main>");
});

it("moves a node from the future", function() {
testFidelity(
`<div><div id="container"><div id="item"></div></div></div>`,
`<div><div id="item"></div><div id="container"></div></div>`,
);
});

it("issue https://github.com/bigskysoftware/idiomorph/issues/11", function () {
let el1 = make('<fieldset id="el"></fieldset>');

Expand Down

0 comments on commit b5b6560

Please sign in to comment.