-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix query input lag #21753
Fix query input lag #21753
Conversation
The debounce in ng-model-options was intended to avoid updating the typeahead suggestions too often. It had the side effect of delaying query input updates to the model on the angular scope. As a result, if you typed quickly and hit enter within 100ms, you would submit an out of date query. This moves the debounce from ng-model-options to the updateSuggestions method itself.
💚 Build Succeeded |
I can confirm this fixes the bug. There is a minor "issue" with the code. If you navigate really fast away from the page while the debounce is still running we'll still trigger a debounce even while we are already on a separate page. Since the debounced function then access the already destroyed scope (calling this.updateSuggestions = debounce(async () => {
const suggestions = await this.getSuggestions();
if (!this._destroyed) {
$scope.$apply(() => this.suggestions = suggestions);
}
});
$scope.$on('$destroy', () => {
this.updateSuggestions.cancel();
this._destroyed = true;
}); I know that code usually is super ugly to read, but also these issues are super hard to detect later on in case they appear, why I think even with a small debounce of 100ms we should rather go for safe cod. We actually hit that issue a couple of times with our render debounce, that is also at 100ms. |
Good point @timroes, I've made the update you suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm, that the reported issue is fixed by this. Code looks also good to me.
💚 Build Succeeded |
The debounce in ng-model-options was intended to avoid updating the typeahead suggestions too often. It had the side effect of delaying query input updates to the model on the angular scope. As a result, if you typed quickly and hit enter within 100ms, you would submit an out of date query. This moves the debounce from ng-model-options to the updateSuggestions method itself.
The debounce in ng-model-options was intended to avoid updating the typeahead suggestions too often. It had the side effect of delaying query input updates to the model on the angular scope. As a result, if you typed quickly and hit enter within 100ms, you would submit an out of date query. This moves the debounce from ng-model-options to the updateSuggestions method itself.
Fixes #20486
The debounce in ng-model-options was intended to avoid updating the
typeahead suggestions too often. It had the side effect of delaying
query input updates to the model on the angular scope. As a result, if
you typed quickly and hit enter within 100ms, you would submit an out of
date query. This moves the debounce from ng-model-options to the
updateSuggestions method itself.