Skip to content

Auto-selection of first item doesn't work with deferred values / suspense queries #250

Closed as not planned

Description

@arvinpoddar

When using a deferred value to make a query (closely referencing the useDeferredValue docs example: https://react.dev/reference/react/useDeferredValue#usage), the first item in the list is not always highlighted when the query results update. Only after additional query refinement will the first result become selected.

We do get the desired behavior if we remove the shouldFilter={false}, but the auto-selection behavior should still work if you're relying on external filtering behavior.

Reproduction CodeSandbox: https://codesandbox.io/p/devbox/cmdk-suspense-9jth8l

Reproduction Video:

Screen.Recording.2024-04-29.at.3.09.10.PM.mov

Thank you!

Activity

  1. updbqn commented on May 23, 2024

    @updbqn
  2. arvinpoddar commented on May 23, 2024

    @arvinpoddar
    Author

    A workaround is to make the Command component controlled and set the selected item yourself when the items change.

    https://codesandbox.io/p/devbox/cmdk-suspense-forked-8qsltv?workspaceId=693b57f1-c881-460c-b8d5-92868a4692cc

    Yep, ultimately the workaround we implemented was something like this, but it feels hacky to have to have a side effect on state to accomplish this. Ideally, the behavior should come baked in with Command if the user is not using it as a controlled component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions