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

Graphical glitch when using async data retrieval and debouncing #441

Closed
tbl0605 opened this issue May 15, 2021 · 6 comments · Fixed by #442
Closed

Graphical glitch when using async data retrieval and debouncing #441

tbl0605 opened this issue May 15, 2021 · 6 comments · Fixed by #442
Assignees
Labels
bug Something isn't working next release This is a thing to include in the next release
Milestone

Comments

@tbl0605
Copy link
Contributor

tbl0605 commented May 15, 2021

Hi,
I recently created an autocomplete component for city names using vue-simple-suggest.
I'm using async data retrieval (https://github.com/KazanExpress/vue-simple-suggest#async-example) and debouncing.
It works great, except that sometimes I have graphical glitches (see my screenshots).
I first thought it was because of the way I'm retrieving the data (or because of axios), but I have same problem when I rewrite my code using the fetch() function.

Step to reproduce:

  1. go to https://codesandbox.io/s/bug-vue-simple-suggest-09ker
  2. try to input 2 or 3 letters. You probably have to try again multiple times, the bug is pretty random, sometimes easy to catch, sometimes it can take a (very) long time
  3. you should see following kind of glitches

vue-simple-suggest
vue-simple-suggest1
vue-simple-suggest2

PS: you can also try the fetch() version, but the bug is harder to reproduce with it: https://codesandbox.io/s/bug-vue-simple-suggest-2-eyuk8

@tbl0605
Copy link
Contributor Author

tbl0605 commented May 15, 2021

I forgot to mention that I can reproduce this bug (at least) on latest versions of Chrome and Firefox :)

@tbl0605
Copy link
Contributor Author

tbl0605 commented May 18, 2021

The issue disappears with my patch (I cannot reproduce the bug anymore).
But you should consider it as a partial fix or workaround, because there is a real deeper problem in your code (I haven't tracked it down), the value of "isPlainSuggestion" seems (sometimes) not to be in sync (or updated soon enough) to reflect latest values retrieved from method getSuggestions().
So my patch will "hide" the real problem but not completly fix it.

For example, before my patch, you could have :

  • "isPlainSuggestion" is set to true because getSuggestions() returned an empty array of values (setting it to true was buggy, my patch fixes that)
  • getSuggestions() is called again and returns a non-empty array of values BUT those list of suggestions is (wrongly) drawn with "isPlainSuggestion" still set to true

Hope I'm clear enough :)

@tbl0605
Copy link
Contributor Author

tbl0605 commented May 19, 2021

My guess for the real problem is that multiple calls to "await this.list(value))" can be done in a very short time and those promises can resolve in any order when the server api is a bit laggy.
Probably getSuggestions() should return an object containing "isPlainSuggestion" and the list of suggestions, so that both would be synchronized and be updated at same time (and neither too early nor too late).

@tbl0605
Copy link
Contributor Author

tbl0605 commented May 20, 2021

Hopefully last comment: I updated my patch so it can be taken as-is, without doing further code changes afterwards, even if I think that "isPlainSuggestion" should be updated outside of getSuggestions() at same time than this.$set(this, 'suggestions', newList)

@kaskar2008
Copy link
Contributor

Hello, @tbl0605
Thanks for the reporting and such a deep dig into the bug :)

@tbl0605
Copy link
Contributor Author

tbl0605 commented Jun 1, 2021

@kaskar2008, would it be possible to make a new release now that this patch is merged?
Thank you for you great work :)

@kaskar2008 kaskar2008 self-assigned this Jun 1, 2021
@kaskar2008 kaskar2008 added bug Something isn't working next release This is a thing to include in the next release labels Jun 1, 2021
@kaskar2008 kaskar2008 added this to the 1.11 milestone Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working next release This is a thing to include in the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants