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
Async search occasionally misses last letters #742
Comments
@ericgio Could you please help to fix this issue. Many thanks in advance. |
I am facing similar issues. What seems to be happening is that the request for "joh" is fired before the request for "john", but the first one takes more time to be returned, and if the previous call is answered after the next call, it overwrites it. |
Check this example, of what I am trying to fix right now. Seems to be exactly what you are facing. You can see that this request taking longer to respond was fired before, but the actual response is after the request called after. So its contents would overwrite the contents returned by the call made after. Of course the server not always takes this much long to answer, that's why you have it depending to typing speed. |
In this example, I am copy pasting the first part "72SR029001" and then typing "@6.95" at the end. I am logging on console the queried value on the As you can see it is not on the correct order, because the less specific query takes longer to return. My approach / workaround to fix it is, when running the function on promise resolution, compare it with the value that is actually on the search field (i.e. Just for the complete reference / answer, you can get that |
Another solution is to use AbortController to cancel any previous pending requests whenever a new one is fired. |
Hi @mdickin I fixed the same behavior as you are facing applying the useCallback hook as reported in the doc. |
@giose86 thanks for that, I think that works for me as well! Hopefully we can get the example in the docs updated accordingly |
Version
6.0.0 (reproduced on http://ericgio.github.io/react-bootstrap-typeahead/#asynchronous-searching)
Have also seen this happen with 5.2.1
Steps to reproduce
This can be hard to reproduce, it seems to depend on typing speed.
Occasionally, typing in the box will lose the last character or two. For instance (see below screenshots), typing "John" will only issue a search request for "joh".
It feels like something to do with the
debounce
function, but from what I've seen in the code, that's configured correctly (leading
andtrailing
arguments aren't specified, so they default to 'false' and 'true' respectively)Expected Behavior
The search will contain all typed in characters (after accounting for any input delay).
Actual Behavior
Results contain a few accounts that don't match "john"
Network inspector
Only one request was issued
The text was updated successfully, but these errors were encountered: