Skip to main content

Search and Top Navigation

#8234 closed feature (fixed)

Opened April 02, 2012 07:55PM UTC

Closed April 03, 2012 08:47PM UTC

Last modified April 03, 2012 11:19PM UTC

Autocomplete: Automatic race-condition handling for custom sources

Reported by: sexconker Owned by: sexconker
Priority: minor Milestone: 1.8.19
Component: ui.autocomplete Version: 1.8.18
Keywords: Cc:
Blocked by: Blocking:
Description

I'm testing with JQuery 1.7.2 and JQueryUI 1.9m7.

I have an autocomplete that hits up page via AJAX.

Regardless of the delay set, I can get a race condition to trigger, but it is easiest to get it to trigger when the delay is 0. It does not depend on whether or not autoFocus is true or false.

For example, quickly typing in "he" will show the result set matching "", or "h" or "he".

Here's a screenshot of it happening.

[[Image(http://i.imgur.com/TKBdx.jpg)]]

The top half of the image shows the correct result set being returned after typing in "he". The bottom half shows the incorrect result set being returned. The result set returned in the bottom half of the image is the correct result set for "h".

The request for "h" does fire off before the request for "he".

[[Image(http://i.imgur.com/9nLu7.jpg)]]

The input no longer has the bug where characters are seemingly deleted. For that behavior, it seemed as if the result was setting the input's value to what it was when the old AJAX request was initiated, thus overriding any typing since that request was made.

It now seems as if the input field's value is set to what it was when the most resent result was sent (fixing the "character deletion" bug), but the incorrect (not the most recent) result set can still show.

See http://bugs.jqueryui.com/ticket/7555 and http://bugs.jqueryui.com/ticket/7926

Attachments (0)
Change History (9)

Changed April 02, 2012 08:11PM UTC by scottgonzalez comment:1

owner: → sexconker
status: newpending

I'm not seeing this at all. I can even see the original request get cancelled. If I remove xhr.abort() and force my requests to always result in the second request completing first, I still see the correct behavior. Please provide a reduced test case showing the problem.

Changed April 02, 2012 11:39PM UTC by sexconker comment:2

status: pendingnew

See http://waitillfixit.com/autocomplete/ .

There is an artificial delay (500 ms) inserted when the search term is 1 character long.

Type in he at a normal speed and you should see the bug. The "h" results take over the "he" results.

Type he slowly and it works fine.

Changed April 03, 2012 01:56AM UTC by scottgonzalez comment:3

summary: More Autocomplete Race ConditionsAutocomplete: Automatic race-condition handling for custom sources
type: bugfeature

Ajax doesn't matter here. You're using a custom source. Also, you shouldn't double filter your results, your server should just return the correct data...

Changed April 03, 2012 04:00AM UTC by sexconker comment:4

Yes, I'm using a custom source, but I'm still feeding back into the response callback as indicated in the docs.

Am I not doing it properly?

Are you able to recreate the bug or not? How is it a "new feature" request to have the result set displayed correspond to the latest request?

The server does return the correct data, this is just a trivial example based on a skeleton of our code. There are a bunch of different checks and options that our full code does, including allowing wildcards, ranges, etc.

Changed April 03, 2012 11:18AM UTC by scottgonzalez comment:5

status: newopen

Custom sources were designed as a very low level solution. The source itself is responsible for everything: gathering data, filtering, parsing, caching, throttling (excluding typing delays), etc.

Changed April 03, 2012 08:47PM UTC by Scott González comment:6

resolution: → fixed
status: openclosed

Autocomplete: Move race condition logic from ajax requests to general response handler. Fixes #8234 - Autocomplete: Automatic race-condition handling for custom sources.

Changeset: 96f9c84b7b2149c6b93ac226a52065652f218e1e

Changed April 03, 2012 08:51PM UTC by Scott González comment:7

Autocomplete: Move race condition logic from ajax requests to general response handler. Fixes #8234 - Autocomplete: Automatic race-condition handling for custom sources.

(cherry picked from commit 96f9c84b7b2149c6b93ac226a52065652f218e1e)

Conflicts:

tests/unit/autocomplete/autocomplete_core.js

ui/jquery.ui.autocomplete.js

Changeset: d040b8f42cc28932deedddebe95473a9fd13d742

Changed April 03, 2012 08:51PM UTC by scottgonzalez comment:8

milestone: 1.91.8.19
version: git1.8.18

Changed April 03, 2012 11:19PM UTC by sexconker comment:9

Thanks for the explanation. I didn't expect the race condition logic to only handle the string version of source. I've wedged in a quick fix based on that code into our custom source for one of our projects where it's a noticeable issue.

When 1.8.19 is rolled out we'll update all our projects.