adobe/react-spectrum

List State: `collection.getItem()` can return `undefined`

Open

#5,776 建立於 2024年1月30日

在 GitHub 查看
 (6 留言) (0 反應) (0 負責人)TypeScript (1,500 fork)auto 404
bughelp wanted

倉庫指標

Star
 (15,634 star)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南