Skip to content

fix(docsearch-react): cache requests and avoid redundant Ask AI refreshes - #25

Merged
tharropoulos merged 2 commits into
typesense:mainfrom
haydenhoang:v5
Oct 6, 2026
Merged

tharropoulos merged 2 commits into
typesense:mainfrom
haydenhoang:v5

Conversation

@haydenhoang

Copy link
Copy Markdown
Collaborator

Changes

  • Enable Typesense caching by default to prevent duplicate requests firing on search box focus which also cause it to lose focus right after. Cache does not expire until page is reloaded, matching Algolia's default.
  • Refresh autocomplete only when returning from Ask AI to keyword search.

This also surfaced an issue in typesense-js client. The SDK should not cache failed request or a 200 multi search response that contain retriable error e.g. 500, 408 time out

For now the docsearch clear all cache when an error occur typesense.multiSearch.clearCache();, this will be removed once upstream is fixed.

@haydenhoang

Copy link
Copy Markdown
Collaborator Author

@tharropoulos could you take a look. This directly affects the new docs-site migration.

@tharropoulos
tharropoulos self-requested a review October 5, 2026 10:29

@tharropoulos tharropoulos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, the ask ai refresh fix is right and caching makes sense. couple of notes

Comment thread packages/docsearch-react/src/useSearchClient.ts
Comment thread packages/docsearch-react/src/useSearchClient.ts Outdated
...typesenseServerConfig,
// Autocomplete refreshes on focus. Cache identical requests and in-flight searches by default.
cacheSearchResultsForSeconds:
typesenseServerConfig.cacheSearchResultsForSeconds ?? Infinity,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi the client lives in the modal's useMemo, so the cache resets every time the modal closes (not on page reload like the description says). inline typesenseServerConfig objects will also rebuild it on rerender

@tharropoulos

Copy link
Copy Markdown
Collaborator

@haydenhoang the new 3.1.1 release of typesense-js includes the fix for the caching, so that line I added a comment on is redundant. Could you bump the deps and check?

@tharropoulos

Copy link
Copy Markdown
Collaborator

lgtm :shipit:

@tharropoulos
tharropoulos merged commit 2081ffe into typesense:main Oct 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants