If source callback is slow, suggest may get the wrong that.val to cache#64
Open
arrbee wants to merge 2 commits intoPixabay:masterfrom
Open
If source callback is slow, suggest may get the wrong that.val to cache#64arrbee wants to merge 2 commits intoPixabay:masterfrom
source callback is slow, suggest may get the wrong that.val to cache#64arrbee wants to merge 2 commits intoPixabay:masterfrom
Conversation
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.
Author
|
I updated this to just wrap the suggest callback in a closure instead of relying on I also regenerated the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the
suggestfunction is passed to thesourcecallback, if the user is still typing, it seems that thethat.valvalue may have changed beforesuggestis called. This can result in caching completions for the incorrectthat.valvalue.For example, I observed when typing "umbrella" that the results for "umb" could be cached against
that.valof "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
suggestfunction and uses.bindat the time the function is passed tosourceto record the value at the time of invocation. This way, when we cache values fromsource, we cache them against the same value that was passed tosourcewhen we invoked it.I'm not sure from this project's README what your policy is on browser support.
Function.prototype.bindworks 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.