Related Changes: Discard late arriving REST API results

Users can load CS2 and open a file before Related Changes is able to
finish its REST API calls and load the panel. If this happens the tab
will be detached from the DOM and cannot measure its correct height,
resulting in CSS failures with "CSS heights should not be negative".

Discard REST results if the widget is no longer attached to the DOM,
as the user has navigated away and does not care anymore.

Change-Id: Iad8303879019570edc67192956d32d7eddb9926e
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/RelatedChanges.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/RelatedChanges.java
index 5f6c6de..353a47f 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/RelatedChanges.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/RelatedChanges.java
@@ -272,19 +272,23 @@
 
     @Override
     public void onSuccess(T result) {
-      JsArray<ChangeAndCommit> changes = convert(result);
-      if (changes.length() > 0) {
-        setTabTitle(tabInfo, tabInfo.getTitle(changes.length()));
-        getTab(tabInfo).setChanges(project, revision, changes);
+      if (isAttached()) {
+        JsArray<ChangeAndCommit> changes = convert(result);
+        if (changes.length() > 0) {
+          setTabTitle(tabInfo, tabInfo.getTitle(changes.length()));
+          getTab(tabInfo).setChanges(project, revision, changes);
+        }
+        onDone(changes.length() > 0);
       }
-      onDone(changes.length() > 0);
     }
 
     @Override
     public void onFailure(Throwable err) {
-      setTabTitle(tabInfo, tabInfo.getTitle(Resources.C.notAvailable()));
-      getTab(tabInfo).setError(err.getMessage());
-      onDone(true);
+      if (isAttached()) {
+        setTabTitle(tabInfo, tabInfo.getTitle(Resources.C.notAvailable()));
+        getTab(tabInfo).setError(err.getMessage());
+        onDone(true);
+      }
     }
 
     private void onDone(boolean enabled) {