Skip to content

useCombobox does not work very well with virtualization #1041

@kentcdodds

Description

@kentcdodds
  • downshift version: latest

What you did:

Tried to combine useCombobox with react-virtual (though I expect this same problem would happen with any virtualization technique.

What happened:

Open up:

https://codesandbox.io/s/brave-einstein-vpvvo

Notice that if you focus the input and arrow down enough times, eventually the scrolling gets wacko.

I don't have a lot of time to explain, but hopefully the example helps you identify the issue.

The solution is to not get the node by the highlightedIndex alone, but by a unique identifier for the item.

So first, change itemRefs.current = [] to itemRefs.current = {}, then change this:

itemRefs.current.push(itemNode)

To this:

itemRefs.current[elementIds.current.getItemId(itemIndex)] = itemNode

And then update everywhere that references the itemRefs.current to retrieve the itemNode via the ID rather than the index. This fixes the bug for me.

Unfortunately, I have to move on and can't work on this myself right now. But hopefully that helps get anyone on the right track. Thanks and good luck!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions