Skip to content

Commit ae36057

Browse files
committed
Use getAttribute when soft matching ids.
Some javascript frameworks like angular can overwrite the tag's id getter, and comparison can turn into a false negative. Newly added elements don't have the framework's code initialised yet, and calling id on those elements can differ from the id assigned via angular. Since there is no way to have frameworks initialized on the new elements, calling the `id` can be inconsistent. Using getAttribute("id") ensures that we always compare the html id attributes.
1 parent a6ada99 commit ae36057

6 files changed

Lines changed: 24 additions & 6 deletions

File tree

dist/idiomorph-ext.esm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@ var Idiomorph = (function () {
476476
// If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing.
477477
// We'll still match an anonymous node with an IDed newElt, though, because if it got this far,
478478
// its not persistent, and new nodes can't have any hidden state.
479-
(!oldElt.id || oldElt.id === newElt.id)
479+
(
480+
(!oldElt.getAttribute("id")) ||
481+
(oldElt.getAttribute("id") === newElt.getAttribute("id"))
482+
)
480483
);
481484
}
482485

dist/idiomorph-ext.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ var Idiomorph = (function () {
474474
// If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing.
475475
// We'll still match an anonymous node with an IDed newElt, though, because if it got this far,
476476
// its not persistent, and new nodes can't have any hidden state.
477-
(!oldElt.id || oldElt.id === newElt.id)
477+
(
478+
(!oldElt.getAttribute("id")) ||
479+
(oldElt.getAttribute("id") === newElt.getAttribute("id"))
480+
)
478481
);
479482
}
480483

dist/idiomorph.cjs.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ var Idiomorph = (function () {
474474
// If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing.
475475
// We'll still match an anonymous node with an IDed newElt, though, because if it got this far,
476476
// its not persistent, and new nodes can't have any hidden state.
477-
(!oldElt.id || oldElt.id === newElt.id)
477+
(
478+
(!oldElt.getAttribute("id")) ||
479+
(oldElt.getAttribute("id") === newElt.getAttribute("id"))
480+
)
478481
);
479482
}
480483

dist/idiomorph.esm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ var Idiomorph = (function () {
474474
// If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing.
475475
// We'll still match an anonymous node with an IDed newElt, though, because if it got this far,
476476
// its not persistent, and new nodes can't have any hidden state.
477-
(!oldElt.id || oldElt.id === newElt.id)
477+
(
478+
(!oldElt.getAttribute("id")) ||
479+
(oldElt.getAttribute("id") === newElt.getAttribute("id"))
480+
)
478481
);
479482
}
480483

dist/idiomorph.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ var Idiomorph = (function () {
474474
// If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing.
475475
// We'll still match an anonymous node with an IDed newElt, though, because if it got this far,
476476
// its not persistent, and new nodes can't have any hidden state.
477-
(!oldElt.id || oldElt.id === newElt.id)
477+
(
478+
(!oldElt.getAttribute("id")) ||
479+
(oldElt.getAttribute("id") === newElt.getAttribute("id"))
480+
)
478481
);
479482
}
480483

src/idiomorph.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ var Idiomorph = (function () {
474474
// If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing.
475475
// We'll still match an anonymous node with an IDed newElt, though, because if it got this far,
476476
// its not persistent, and new nodes can't have any hidden state.
477-
(!oldElt.id || oldElt.id === newElt.id)
477+
(
478+
(!oldElt.getAttribute("id")) ||
479+
(oldElt.getAttribute("id") === newElt.getAttribute("id"))
480+
)
478481
);
479482
}
480483

0 commit comments

Comments
 (0)