Bug 1420291 - instanciate RequestListContextMenu lazily draft
authorTom Glowka <glowka.tom@gmail.com>
Fri, 16 Mar 2018 16:19:36 +0100
changeset 769547 f23d5c476c34
parent 769320 4f1014eb5039
push id103172
push userbmo:glowka.tom@gmail.com
push dateMon, 19 Mar 2018 20:30:42 +0000
bugs1420291
milestone61.0a1
Bug 1420291 - instanciate RequestListContextMenu lazily MozReview-Commit-ID: Db6fgkHJD1v
devtools/client/netmonitor/src/components/RequestListContent.js
--- a/devtools/client/netmonitor/src/components/RequestListContent.js
+++ b/devtools/client/netmonitor/src/components/RequestListContent.js
@@ -75,22 +75,16 @@ class RequestListContent extends Compone
     this.onScroll = this.onScroll.bind(this);
     this.onResize = this.onResize.bind(this);
     this.onKeyDown = this.onKeyDown.bind(this);
     this.onContextMenu = this.onContextMenu.bind(this);
     this.onFocusedNodeChange = this.onFocusedNodeChange.bind(this);
   }
 
   componentWillMount() {
-    const { connector, cloneSelectedRequest, openStatistics } = this.props;
-    this.contextMenu = new RequestListContextMenu({
-      connector,
-      cloneSelectedRequest,
-      openStatistics,
-    });
     this.tooltip = new HTMLTooltip(window.parent.document, { type: "arrow" });
     window.addEventListener("resize", this.onResize);
   }
 
   componentDidMount() {
     // Install event handler for displaying a tooltip
     this.tooltip.startTogglingOnHover(this.refs.contentEl, this.onHover, {
       toggleDelay: REQUESTS_TOOLTIP_TOGGLE_DELAY,
@@ -239,16 +233,26 @@ class RequestListContent extends Compone
       evt.stopPropagation();
       this.props.onSelectDelta(delta);
     }
   }
 
   onContextMenu(evt) {
     evt.preventDefault();
     let { selectedRequest, displayedRequests } = this.props;
+
+    if (!this.contextMenu) {
+      const { connector, cloneSelectedRequest, openStatistics } = this.props;
+      this.contextMenu = new RequestListContextMenu({
+        connector,
+        cloneSelectedRequest,
+        openStatistics,
+      });
+    }
+
     this.contextMenu.open(evt, selectedRequest, displayedRequests);
   }
 
   /**
    * If selection has just changed (by keyboard navigation), don't keep the list
    * scrolled to bottom, but allow scrolling up with the selection.
    */
   onFocusedNodeChange() {