Bug 1521097 - Bug 1480057 follow-up: Don't use .label when the XBL binding isn't attached yet. r=florian
authorJorg K <jorgk@jorgk.com>
Mon, 21 Jan 2019 10:52:10 +0100
changeset 34256 611baef2655fa4f370f2494b0126bfbbf738327f
parent 34255 bf2126d1ba5c199f4f3c92baac8bd519bd828905
child 34257 fe3c8a49ad2ff4bddd158dd42211eef464fefb2c
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersflorian
bugs1521097, 1480057
Bug 1521097 - Bug 1480057 follow-up: Don't use .label when the XBL binding isn't attached yet. r=florian
mail/components/im/content/imconversation.xml
--- a/mail/components/im/content/imconversation.xml
+++ b/mail/components/im/content/imconversation.xml
@@ -1105,16 +1105,17 @@
          this.trackNick(name);
 
          let image = document.createElement("image");
          let label = document.createElement("label");
          label.setAttribute("value", name);
          label.setAttribute("flex", "1");
          label.setAttribute("crop", "end");
 
+         // Fix addNick below if you change the DOM makeup!
          var item = document.createElement("richlistitem");
          item.chatBuddy = aBuddy;
          item.appendChild(image);
          item.appendChild(label);
          this.setBuddyAttributes(item);
 
          var color = this._computeColor(name);
          var style = "color: hsl(" + color + ", 100%, 40%);";
@@ -1139,17 +1140,21 @@
          var nicklist = document.getElementById("nicklist");
          var nick = aListItem.querySelector("label").value.toLowerCase();
 
          // Look for the place of the nick in the list
          var start = 0;
          var end = nicklist.itemCount;
          while (start < end) {
            var middle = start + Math.floor((end - start) / 2);
-           if (nick < nicklist.getItemAtIndex(middle).label.toLowerCase())
+           // .firstChild.nextSibling gets us to the label. We can't use
+           // .label since the XBL binding might not be attached yet.
+           if (nick < nicklist.getItemAtIndex(middle)
+                              .firstChild.nextSibling
+                              .getAttribute("value").toLowerCase())
              end = middle;
            else
              start = middle + 1;
          }
 
          // Now insert the element
          if (end == nicklist.itemCount)
            nicklist.appendChild(aListItem);