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

[AutoComplete] Race Condition on Remote Long Queries #10

Open
SkyeHoefling opened this issue Sep 5, 2018 · 2 comments
Open

[AutoComplete] Race Condition on Remote Long Queries #10

SkyeHoefling opened this issue Sep 5, 2018 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@SkyeHoefling
Copy link
Contributor

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);
});
@SkyeHoefling SkyeHoefling self-assigned this Sep 5, 2018
@SkyeHoefling SkyeHoefling added the bug Something isn't working label Sep 5, 2018
@SkyeHoefling
Copy link
Contributor Author

I have a fix for this in https://github.com/HoeflingSoftware/nvQuickComponents/tree/autocomplete-race-condition.

Once #9 is merged I will create a PR for this since it is dependent on that code change

@david-poindexter
Copy link
Member

#9 was merged. With this PR go ahead and include the build so we will have a working /dist folder. Then we can circle back to #3 and set a path forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants