JedWatson / JedWatson/react-select

Async: defaultOptions={true} gives strange behaviour when lodash debounce function is in use

Open
#5,359 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

issue/bug-unconfirmed
Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Hello,

I noticed that AsyncSelect behaviour is weird when I use a lodash debounce function together with defaultOptions={true}. When I use keyboard to focus the Select component, I can start typing and both loading state in the menu and options appear as intended. However, when I click the Select component, I can see a Loading state in the Menu for a moment which I think isn't supposed to be visible and then it disappears. Looks like there is some difference in handling this between onClick and onFocus events.

Here is a Sandbox where you can check this bug.

How to reproduce?
  1. On first render click on AsyncSelect with an empty input
  2. Menu with Loading state appears which is not an intended behaviour. If the Menu with Loading doesn't appear, try reloading the page and it will be there.
  3. After that component works as intended. Loading state doesn't appear on next clicks with an empty input.
Can be compared to the keyboard behaviour:
  1. On first render Tab to AsyncSelect
  2. Menu with Loading state doesn't appear
  3. Component works as intended

Are you reporting a bug or runtime error?

Bug

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox and compare the first click path with the keyboard-focus path for AsyncSelect using defaultOptions={true} and lodash debounce. Trace the onClick and onFocus handling involved in the initial loading state; done means the menu does not briefly show Loading on the first click while preserving the intended keyboard behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.