With near-simultaneous inputs (e.g. holding down the backspace key
while deleting text) you can cause the suggestion promise to resolve
out-of-order. This causes apparently incorrect suggestions to be
displayed for the current input.
To fix this, abort the existing promise if it exists.
Bug: T114178
Change-Id: I9332452fd914b54e7c564284da2a8a00865ae806
mw.widgets.TitleSearchWidget.prototype.onQueryChange = function () {
var widget = this;
- this.getSuggestionsPromise().done( function ( response ) {
+ if ( this.currentRequest ) {
+ this.currentRequest.abort();
+ }
+
+ this.currentRequest = this.getSuggestionsPromise();
+ this.currentRequest.done( function ( response ) {
// Parent method
mw.widgets.TitleSearchWidget.parent.prototype.onQueryChange.call( widget );
widget.results.addItems( widget.getOptionsFromData( response.query || {} ) );
+
+ widget.currentRequest = false;
} );
};