algolia / autocomplete

🔮 Fast and full-featured autocomplete library
https://alg.li/autocomplete
MIT License
4.96k stars 328 forks source link

onSelect item should trigger store.pendingRequests.cancelAll(); #1207

Open AntoineDuComptoirDesPharmacies opened 8 months ago

AntoineDuComptoirDesPharmacies commented 8 months ago

Description

Following of this issue : #806, when we programatically call setIsOpen(false) to the Autocomplete instance, the current requests are not cancelled and the panel re-open when queries finish.

Reproduction

Preview →

Steps

  1. Go to the code sandbox
  2. Click on the Search and type 'd', wait for results to display
  3. Pass your browser network in slow mode
  4. Type 'deb' in the search bar and immediately select an item from the previous search (that will trigger a setIsOpen(false) + history.push to bring you to the item subpage)
  5. React router change the components of the user, the search is correctly closed
  6. As requests are not cancelled, when one finish, the autocomplete panel re-open

Expected behavior

When the autocomplete isOpen become false, all existing queries should be cancelled so the autocomplete panel re-open only if the input take focus again.

Environment

Haroenv commented 8 months ago

I believe that redirects may rely on the request not being cancelled (at least available in the results), but it should indeed prevent to reopen though