Skip to content

[AutoComplete] Race Condition on Remote Long Queries #10

@SkyeHoefling

Description

@SkyeHoefling

If you are using the autocomplete control with a remote endpoint to populate the results there can be a race condition if it takes your result some time to respond. See the example below with steps to reproduce

  1. Start typing into auto complete (the first char or first 2 char may be an expensive query)
  2. Continue typing until you get to 3 or 4+ chars where the query is much faster
  3. Wait

Expected Result

  • The autocomplete should show the correct records for the given input

Actual Result

  • The autocomplete shows the correct records
  • After a brief amount of time it flashes to incorrect records for a query that was waiting

Root Cause
There is a race condition happening with the getRemoteResults invocation which overrides results. We should add some code to the callback (maybe promise handling) to drop requests if they are not the latest.

The problem has to do with this invocation and callback

getRemoteResults(input, (remoteItemsSource) => {
    let results:HTMLElement[] = [];
    for (let index in remoteItemsSource) {
        let currentElement:HTMLElement = buildAutoCompleteItem(remoteItemsSource[index]);
        results.push(currentElement);
    }

    hydrateAutocomplete(results);
});

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions