List State: `collection.getItem()` can return `undefined`
- Dominant language
- TypeScript
- Stars
- 15.9k
- Forks
- 1.6k
- Avg merge
- 3d 9m
- Merged PRs (30d)
- 59
Description
### Provide a general summary of the issue here
Well. I have a very hard to reproduce bug - it's randomly happening - and hard to check in the current repo the returned type. So, I build a Combobox thanks to the hooks and load async some data to fill the items - with or without useAsyncList btw - and sometimes I receive:
```
Uncaught TypeError: Cannot read properties of undefined (reading 'index')
at useListState.ts:81:21
```
so looks like that here https://github.com/adobe/react-spectrum/blob/b5974ad1ccf2abc984c5cc6664b3c2d03de36768/packages/%40react-stately/list/src/useListState.ts#L63 `collection.getItem()` can return `undefined`
### 🤔 Expected Behavior?
It doesn't crash ^_^
### 😯 Current Behavior
It does crash :-/
### 💁 Possible Solution
_No response_
### 🔦 Context
_No response_
### 🖥️ Steps to Reproduce
It's a very hard issue to reproduce and hard to have an easy example unfortunately.
I can't have a setup with the current reop that returns another type that "any", so it's really hard to find out what happens.
The only thing I know it that you need to:
- open the combobox
- put some text (not necessarily needed)
- select an item
- it reloads the items list because filterText changed (set by the selection)
- clean the selected Item
- it reloads the first 50 items (filterText = "")
- repeat
as fast as you can to trigger it. I feel like checking the possible returned value of `getItem` would be easier but I was unsuccessful here.
### Version
latest
### What browsers are you seeing the problem on?
Chrome
### If other, please specify.
_No response_
### What operating system are you using?
Windows
### 🧢 Your Company/Team
_No response_
### 🕷 Tracking Issue
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.