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
This commit is contained in:
Shawn Pearce 2015-01-14 16:42:17 -08:00
parent c09bad2917
commit d9d64ecd6a

View File

@ -272,19 +272,23 @@ public class RelatedChanges extends TabPanel {
@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) {