Skip to content

Commit 25001df

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 uid=501(dombesz) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),702(com.apple.sharepoint.group.2),701(com.apple.sharepoint.group.1),33(_appstore),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),400(com.apple.access_remote_ae) can be inconsistent. Using getAttribute("id") ensures that we always compare the html id attributes. Lint changes
1 parent a6ada99 commit 25001df

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/idiomorph.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,20 @@ var Idiomorph = (function () {
468468
const oldElt = /** @type {Element} */ (oldNode);
469469
const newElt = /** @type {Element} */ (newNode);
470470

471+
const oldEltId =
472+
/** @type {boolean | string} */
473+
(oldElt instanceof Element) && oldElt.getAttribute("id");
474+
const newEltId =
475+
/** @type {boolean | string} */
476+
(newElt instanceof Element) && newElt.getAttribute("id");
477+
471478
return (
472479
oldElt.nodeType === newElt.nodeType &&
473480
oldElt.tagName === newElt.tagName &&
474-
// If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing.
481+
// If oldEltId is present with possible state and it doesn't match newEltId then avoid morphing.
475482
// We'll still match an anonymous node with an IDed newElt, though, because if it got this far,
476483
// its not persistent, and new nodes can't have any hidden state.
477-
(!oldElt.id || oldElt.id === newElt.id)
484+
(!oldEltId || oldEltId === newEltId)
478485
);
479486
}
480487

0 commit comments

Comments
 (0)