cmdk
cmdk copied to clipboard
Command score computation extremely slow when item values are variable
I saw in one of the threads to support an always-present item like "New item" in a list of items, to use <Command.Item value={inputValue} />
so it's always in the filtered + ranked list
However, the default computation gets very slow with long inputs as you type more and more
Repro: https://codesandbox.io/s/xenodochial-poitras-d6nn6s?file=/src/App.tsx
- Focus input
- Type random garbage, like 'alksdjf lkawejf lkawej klawef lakwejf lkawejf lkawejf klawejf lkawejf lkawejf lkawejfl;kawefal;w efj;alkwe fklawje flkajwe flkawje flkawje f;lakwje f;lakwje flkawje fklawje fklajw elfja wekfl jaweklfj aklwej aklwejawe'
- Notice you start dropping tons of frames due to commandScore calculations taking 1+ seconds
Note this still happens even if you set shouldFilter = false
It's circumventable if you provide a custom filter function, though! So I am not blocked
OK I guess i didn't need to dynamically change Command.Item value if I'm doing custom filtering anyway... :D
but I think if you set shouldFilter={false} it shouldnt run command-score, no?
I also ran into this when rendering a dynamic Command.Item which matched the input value:
<Command.Item value={inputValue} />
Even with filtering={false}
the custom filtering continued to run and drop frames.
As @tarngerine said, provide a custom filter function to work around it. e.g:
<CommandPrimitive shouldFilter={false} filter={() => 1} />