Bug 1371721 - Resolve dispatchMessageAdd promise only when the related message is logged. r=nchevobbe draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 19 Sep 2017 11:04:29 +0200
changeset 668435 37527ecf1d679616329fbb7b6b78c6984b3256bd
parent 668434 aaa9cfac0a09daafaff93447846eba2e2149d3f1
child 732700 0bb7dec07ea1bdc016570c6235fe1c30f0851027
push id81044
push userbmo:poirot.alex@gmail.com
push dateThu, 21 Sep 2017 17:00:48 +0000
reviewersnchevobbe
bugs1371721
milestone57.0a1
Bug 1371721 - Resolve dispatchMessageAdd promise only when the related message is logged. r=nchevobbe `timeStamp` was no longer passed with `new-messages` event. MozReview-Commit-ID: 6yF9B6CSrPs
devtools/client/webconsole/new-console-output/components/message.js
devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
--- a/devtools/client/webconsole/new-console-output/components/message.js
+++ b/devtools/client/webconsole/new-console-output/components/message.js
@@ -73,17 +73,17 @@ const Message = createClass({
     if (this.messageNode) {
       if (this.props.scrollToMessage) {
         this.messageNode.scrollIntoView();
       }
       // Event used in tests. Some message types don't pass it in because existing tests
       // did not emit for them.
       if (this.props.serviceContainer) {
         this.props.serviceContainer.emitNewMessage(
-          this.messageNode, this.props.messageId);
+          this.messageNode, this.props.messageId, this.props.timeStamp);
       }
     }
   },
 
   onLearnMoreClick: function () {
     let {exceptionDocURL} = this.props;
     this.props.serviceContainer.openLink(exceptionDocURL);
   },
--- a/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
+++ b/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
@@ -70,20 +70,21 @@ NewConsoleOutputWrapper.prototype = {
         return;
       }
 
       this.jsterm.focus();
     });
 
     const serviceContainer = {
       attachRefToHud,
-      emitNewMessage: (node, messageId) => {
+      emitNewMessage: (node, messageId, timeStamp) => {
         this.jsterm.hud.emit("new-messages", new Set([{
           node,
           messageId,
+          timeStamp,
         }]));
       },
       hudProxy: this.jsterm.hud.proxy,
       openLink: url => {
         this.jsterm.hud.owner.openLink(url);
       },
       createElement: nodename => {
         return this.document.createElementNS("http://www.w3.org/1999/xhtml", nodename);
@@ -177,39 +178,42 @@ NewConsoleOutputWrapper.prototype = {
         {className: "webconsole-output-wrapper"},
         filterBar,
         childComponent
     ));
     this.body = ReactDOM.render(provider, this.parentNode);
 
     this.jsterm.focus();
   },
+
   dispatchMessageAdd: function (message, waitForResponse) {
-    this.batchedMessagesAdd(message);
     // Wait for the message to render to resolve with the DOM node.
     // This is just for backwards compatibility with old tests, and should
     // be removed once it's not needed anymore.
     // Can only wait for response if the action contains a valid message.
+    let promise;
     if (waitForResponse) {
-      let {timeStamp} = message;
-      return new Promise(resolve => {
+      promise = new Promise(resolve => {
         let jsterm = this.jsterm;
         jsterm.hud.on("new-messages", function onThisMessage(e, messages) {
           for (let m of messages) {
-            if (m.timeStamp === timeStamp) {
+            if (m.timeStamp === message.timestamp) {
               resolve(m.node);
               jsterm.hud.off("new-messages", onThisMessage);
               return;
             }
           }
         });
       });
+    } else {
+      promise = Promise.resolve();
     }
 
-    return Promise.resolve();
+    this.batchedMessagesAdd(message);
+    return promise;
   },
 
   dispatchMessagesAdd: function (messages) {
     store.dispatch(actions.messagesAdd(messages));
   },
 
   dispatchMessagesClear: function () {
     store.dispatch(actions.messagesClear());