Skip to content
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

If source callback is slow, suggest may get the wrong that.val to cache #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arrbee
Copy link

@arrbee arrbee commented Aug 21, 2016

When the suggest function is passed to the source callback, if the user is still typing, it seems that the that.val value may have changed before suggest is called. This can result in caching completions for the incorrect that.val value.

For example, I observed when typing "umbrella" that the results for "umb" could be cached against that.val of "umbr" and then incorrect results would be displayed if I deleted letters from the end of the full word.

This PR adds the value for which we are looking for suggestions as a parameter to the suggest function and uses .bind at the time the function is passed to source to record the value at the time of invocation. This way, when we cache values from source, we cache them against the same value that was passed to source when we invoked it.

I'm not sure from this project's README what your policy is on browser support. Function.prototype.bind works on all modern browsers, but breaks on IE8 and earlier, for example. Will that prevent you from accepting this PR? If so, I can work around it.

arrbee added 2 commits August 20, 2016 20:41
When the 'suggest' function is passed to the 'source' callback,
there is a race condition that can result in caching the suggested
completions against a value that has since been updated.  Instead,
we add the current value for which we are asking for suggestions
as a parameter to the 'suggest' function and bind the value at the
time of making the 'source' callback.
@arrbee
Copy link
Author

arrbee commented Aug 23, 2016

I updated this to just wrap the suggest callback in a closure instead of relying on .bind() being available. That should maximize compatibility.

I also regenerated the jquery.auto-complete.min.js file since it seems that the last PR you accepted had also regenerated that file. I'm not sure what your policy is on updating the version number. Let me know and I'm happy to fix it up as you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant