Don't query typeahead for one-char inputs

Summary:
The typeahead gives poor results when you only type one character, and those queries are much slower than two+ character queries.

Let's just limit our fetch to only happen for 2+ characters typed.

Some typeaheads even limit to 3+, but I think we can handle 2+.

Reviewed By: quark-zju

Differential Revision: D45665010

fbshipit-source-id: e4743550ee33352fd3a0cbe6f1df974513d1ec40
This commit is contained in:
Evan Krause 2023-05-08 15:30:28 -07:00 committed by Facebook GitHub Bot
parent 5a54b96cff
commit 3913e7a1ab

View File

@ -185,8 +185,9 @@ async function fetchNewSuggestions(
text: string,
): Promise<{values: Array<TypeaheadResult>; fetchStartTimestamp: number}> {
const now = Date.now();
if (text.trim() === '') {
// no need to do a fetch on empty input
if (text.trim().length < 2) {
// no need to do a fetch on zero- or one-char input...
// it's slow and doesn't give good suggestions anyway
return {values: [], fetchStartTimestamp: now};
}
const id = randomId();