From 25001df668e55e44bcb0793dbd8085db11e79253 Mon Sep 17 00:00:00 2001 From: Dombi Attila <83396+dombesz@users.noreply.github.com> Date: Tue, 11 Mar 2025 21:21:24 +0200 Subject: [PATCH] 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 --- src/idiomorph.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/idiomorph.js b/src/idiomorph.js index 83bccf6..08cce29 100644 --- a/src/idiomorph.js +++ b/src/idiomorph.js @@ -468,13 +468,20 @@ var Idiomorph = (function () { const oldElt = /** @type {Element} */ (oldNode); const newElt = /** @type {Element} */ (newNode); + const oldEltId = + /** @type {boolean | string} */ + (oldElt instanceof Element) && oldElt.getAttribute("id"); + const newEltId = + /** @type {boolean | string} */ + (newElt instanceof Element) && newElt.getAttribute("id"); + return ( oldElt.nodeType === newElt.nodeType && oldElt.tagName === newElt.tagName && - // If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing. + // If oldEltId is present with possible state and it doesn't match newEltId then avoid morphing. // We'll still match an anonymous node with an IDed newElt, though, because if it got this far, // its not persistent, and new nodes can't have any hidden state. - (!oldElt.id || oldElt.id === newElt.id) + (!oldEltId || oldEltId === newEltId) ); }