Skip to content

fix(combobox): re-open menu when async items arrive after empty response#9823

Open
costajohnt wants to merge 2 commits intoadobe:mainfrom
costajohnt:fix/combobox-async-empty-reopen
Open

fix(combobox): re-open menu when async items arrive after empty response#9823
costajohnt wants to merge 2 commits intoadobe:mainfrom
costajohnt:fix/combobox-async-empty-reopen

Conversation

@costajohnt
Copy link
Contributor

Summary

Fixes #9820

When using useComboBox with useAsyncList, if a query returns zero results (e.g. typing "luka" against a Star Wars API), the menu closes. Subsequent queries that return results (e.g. backspacing to "luk" which matches "Luke Skywalker") fail to re-open the menu because the inputValue tracking has already been updated by the time the async items arrive.

The root cause is an asymmetry between the open() function (which has a || props.items guard to allow opening with controlled empty collections) and the auto-close check in the useEffect (which closes unconditionally when filteredCollection.size === 0).

The fix tracks when the menu was auto-closed due to an empty controlled collection and re-opens it when items become non-empty while the input is still focused. The flag is reset on user-initiated closes (blur, Escape, commit) so those remain permanent.

Note: the @react-spectrum/combobox component already works around this by auto-setting allowsEmptyCollection: true when loadingState is provided, but direct hook users (useComboBox + useComboBoxState) and RAC ComboBox users don't get this automatic behavior.

Test plan

  • Added test: menu re-opens when controlled items go from empty to non-empty while focused
  • Added test: uncontrolled items still close the menu on empty (regression guard)
  • All 276 existing combobox tests pass across 4 suites (useComboBoxState, useComboBox, RAC ComboBox, Spectrum ComboBox)

Closes #9820

…empty response

When using useComboBox with useAsyncList, if a query returns zero results
the menu closes. A subsequent query that returns results fails to re-open
the menu because the inputValue tracking has already been updated by the
time the async items arrive.

Track when the menu was auto-closed due to an empty controlled collection
and re-open it when items become non-empty while the input is still focused.
Reset the flag on user-initiated closes (blur, Escape, commit) so those
remain permanent.

Fixes adobe#9820
- Reset closedDueToEmptyControlled in revert() so Escape prevents
  re-opening when async items arrive after user dismissal
- Add test for Escape key scenario
- Add onOpenChange assertion for trigger reason on re-open
- Fix minor style: use direct variable instead of destructured object literal
@costajohnt costajohnt marked this pull request as ready for review March 22, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useComboBox + useAsyncList does not show results after a call that was after a call that returned an empty list

1 participant