Bug 1427950 - Only use the mutation observer for migrating new option children to the popup. r=jaws draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 29 Jan 2018 21:14:40 -0800
changeset 749039 7ed2401be658abcb15bdae3f8545450983904fa8
parent 749038 df382271d36bbed6c474fb39aafe73e4d46e080a
child 749040 740d26b1dff83c171575da666c4571a18cd5aa98
push id97299
push usermozilla@noorenberghe.ca
push dateTue, 30 Jan 2018 21:24:25 +0000
reviewersjaws
bugs1427950
milestone60.0a1
Bug 1427950 - Only use the mutation observer for migrating new option children to the popup. r=jaws This reduces the side-effects of render (which should ideally be pure) and should improve performance. We already have the mutation observer anyways. MozReview-Commit-ID: KVhCVEhSvhi
toolkit/components/payments/res/components/rich-select.js
--- a/toolkit/components/payments/res/components/rich-select.js
+++ b/toolkit/components/payments/res/components/rich-select.js
@@ -47,16 +47,22 @@ class RichSelect extends ObservedPropert
       childList: true,
     });
   }
 
   connectedCallback() {
     this.tabIndex = 0;
     this.appendChild(this.popupBox);
 
+    // Move options initially placed inside the select to the popup box.
+    let options = this.querySelectorAll(":scope > .rich-option:not(.rich-select-selected-clone)");
+    for (let option of options) {
+      this.popupBox.appendChild(option);
+    }
+
     this.render();
   }
 
   get selectedOption() {
     return this.popupBox.querySelector(":scope > [selected]");
   }
 
 
@@ -166,21 +172,16 @@ class RichSelect extends ObservedPropert
         return false;
       }
     }
 
     return true;
   }
 
   render() {
-    let options = this.querySelectorAll(":scope > .rich-option:not(.rich-select-selected-clone)");
-    for (let option of options) {
-      this.popupBox.appendChild(option);
-    }
-
     let selectedChild;
     for (let child of this.popupBox.children) {
       if (child.selected) {
         selectedChild = child;
         break;
       }
     }