algolia / algolia/autocomplete
onSelect() called after getSources(), causing a closing delay of the dropdown
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 341
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 5
Description
## Description
When selecting an item a new getSources is triggered (new sources are fetched) and is resolved before calling onSelect(). When working with slow API it prevent the dropdown to be closed while the data is fetched.
## Reproduction
[Preview of the problem](https://codesandbox.io/s/demo-slow-autocomplete-xkhjwl?file=/app.ts)
**Steps**
1. Go on the codesandbox demo
2. Fill the field with a street name "128 Aven" (it's in french)
3. Wait till the suggestions appears
4. Click on a suggestion and see how it load before calling onSelect
## Expected behavior
I expect the autocomplete to close immediately when selecting a value.
I expect onSelect to be called before the new getSources call (it would allow me to prevent loading new async data).
## Environment
- OS: All
- Browser: All
- Autocomplete version: 1.10.0
Contributor guide
Research direction
Start with the linked CodeSandbox reproduction and trace the selection flow involving getSources() and onSelect(). Confirm the ordering that causes the delay, then verify that selecting a suggestion closes the dropdown immediately, calls onSelect() before the subsequent getSources() request, and preserves the expected behavior with slow async data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100