From 6e1074ec4d35ac7cb362cdd16bb62a4293bf032c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Thu, 9 Apr 2026 17:43:14 +0200 Subject: [PATCH] Reduce search debounce (#4170) --- .../gitbook/src/components/Search/useSearchResults.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/gitbook/src/components/Search/useSearchResults.ts b/packages/gitbook/src/components/Search/useSearchResults.ts index a9bca5191..496b4ee93 100644 --- a/packages/gitbook/src/components/Search/useSearchResults.ts +++ b/packages/gitbook/src/components/Search/useSearchResults.ts @@ -8,6 +8,7 @@ import { streamRecommendedQuestions } from './server-actions'; import { type Assistant, useAI } from '@/components/AI'; import assertNever from 'assert-never'; +import { useEventCallback } from 'usehooks-ts'; import { useTrackEvent } from '../Insights'; import { isQuestion } from './isQuestion'; import type { SearchScope } from './useSearch'; @@ -47,6 +48,7 @@ export function useSearchResults(props: { }>({ results: [], fetching: false, error: false }); const { assistants } = useAI(); + const getAssistants = useEventCallback(() => assistants); const withAI = assistants.length > 0; React.useEffect(() => { @@ -134,7 +136,7 @@ export function useSearchResults(props: { }; } setResultsState({ - results: withAI ? withAskTriggers([], query, assistants) : [], + results: withAI ? withAskTriggers([], query, getAssistants()) : [], fetching: true, error: false, }); @@ -179,7 +181,7 @@ export function useSearchResults(props: { } const aiEnrichedResults = withAI - ? withAskTriggers(results, query, assistants) + ? withAskTriggers(results, query, getAssistants()) : results; setResultsState({ results: aiEnrichedResults, fetching: false, error: false }); @@ -195,7 +197,7 @@ export function useSearchResults(props: { } setResultsState({ results: [], fetching: false, error: true }); } - }, 350); + }, 200); return () => { cancelled = true; @@ -212,6 +214,7 @@ export function useSearchResults(props: { disabled, suggestions, searchURL, + getAssistants, ]); return resultsState;