question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autocomplete options misbehaving / duplicating when being used fast, repeatedly or with pasted content (cache related?)

See original GitHub issue

Reproduction

https://formkit.link/c99d6d313aa88c350bff3f71b2a50a67

Describe the bug

I don’t really know how to describe the bug, so I just used the examples & try to explain with them. While below I use “Lord of the Rings: The Two Towers”, which would be rather an edge case that someone uses it like that, this also happens when you use 1 letter, quickly write e.x. “G” and then either copy / select / paste or delete / write, etc. This happens a lot. It is not hard evidence, but I asked a friend to try my form and he discovered this immediately.

  1. Open Playground
  2. Enter or Paste “Lord of the Rings: The Two Towers”
  3. Select the entered text
  4. Copy / Paste it again

=> Now you have multiple entries.

image


Why is this even more a problem?

When writing e.x. “G”, the func returns the results, when you delete “G” the result is still there (assume a cached version) when you click on the autocomplete. This + the above combined creates a pretty strange user experience. If you know have a method that depends on a value like so:

(usually you would use getCities: async ({ search, page, hasNextPage }), but you do not have access to the model value at that point)

getCities: async (input) => {
        const search = input.searchValue;
        if (search === "")
            return [];

        const take = 20;
        const gqlPage = input.page - 1;
        const whereClause = "startsWith" //todo: could also be contains
        const countryId = input.node.parent.value.countryId; //<--- watch here

        return Promise.resolve({data:{hasNextPage:true,items:[]}}/*logic to get data*/).then(e => {
            if (e.data.hasNextPage)
                hasNextPage();

            return e.data.items.map(e => {
                return {
                    value: e.id,
                    label: e.name
                }
            });
        })
    }

You have the issue that if you get the duplicate “options” entries, that they can have the same label but different value, as there is a cached version from before shown.

I hope it is somehow understandable. I am sorry for not being able to provide more details. I can’t debug the pro “autocomplete” code. Willing to show problem live.

Environment

• OS: Windows • Browser: Chrome • Version: 106.0.5249.119

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:27 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
ThatDevelopercommented, Oct 27, 2022

@sashamilenkovic Awesome. Just notify me when it is solved. Don’t need it today. 😃

0reactions
ThatDevelopercommented, Oct 28, 2022

@sashamilenkovic It looks like it is working now. Closing the issue, thank you very much. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autocomplete options misbehaving / duplicating when being ...
Autocomplete options misbehaving / duplicating when being used fast, repeatedly or with pasted content (cache related?)
Read more >
[Autocomplete] Not working properly with repeated options ...
Just to add here, I believe there is a use case for 'duplicate' options. The scenario is where we want distinct options to...
Read more >
Fixed: Autocomplete is messed up in Outlook - Slipstick Systems
Users are reporting a problem in Outlook 2019, 2016, and Outlook 365: the autocomplete list is messed up. It may open upward, not...
Read more >
material-ui autocomplete duplicate key warning - Stack Overflow
To get rid of the duplicate key warning, the text property must be unique because this is what's used to create the React...
Read more >
'RTC Connecting' Stuck in Discord [FIXED] — Auslogics Blog
1. Check Your Internet Connection. 2. Restart Your Devices. 3. Check Your VPN.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found