Skip to content

fix(website): handle synchronous Orama v3 search API in docs search - #18

Merged
IamCoder18 merged 2 commits into
mainfrom
fix/website-search-orama-v3
Sep 13, 2026
Merged

IamCoder18 merged 2 commits into
mainfrom
fix/website-search-orama-v3

Conversation

@IamCoder18

Copy link
Copy Markdown
Owner

Summary

  • Fix Uncaught TypeError: Dr(...).then is not a function in the docs search dialog (⌘K)

Orama v3 (3.1.18) returns search() results synchronously in the browser, but Search.tsx was written for the v2 async API and chained .then() on the plain results object. The throw happened before .catch() could attach, so it crashed the component uncaught.

Changes

  • Call search() directly and read the result, with an instanceof Promise guard so either API shape works
  • Wrap the call in try/catch, falling back to no hits on error
  • Type db state as AnyOrama (the previous Awaited<ReturnType<typeof create>> triggered TS2589 with v3 generics)

Verification

  • tsc --noEmit clean (pre-existing astro.config.mjs error unrelated)
  • astro build succeeds; new bundle calls search synchronously
  • Smoke test with real dist/search.json: sync results, hits returned for SafeOpMode

Orama v3 returns search results synchronously in the browser, so calling
.then() on the result threw 'then is not a function' and crashed the
search dialog. Call search() directly with a Promise guard and try/catch.
@coderabbitai

coderabbitai Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 49 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: eb27516b-8688-4b4f-9a67-8535307bb7ea

📥 Commits

Reviewing files that changed from the base of the PR and between bb376c3 and c97ae6a.

⛔ Files ignored due to path filters (1)
  • website/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • website/package.json
  • website/src/components/react/Search.tsx

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: b0e8035a-ecc2-4d35-b150-bcf130317a92

📥 Commits

Reviewing files that changed from the base of the PR and between f079334 and bb376c3.

📒 Files selected for processing (1)
  • website/src/components/react/Search.tsx

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Build (PR only)
  • GitHub Check: Kilo Code Review
🔇 Additional comments (1)
website/src/components/react/Search.tsx (1)

2-2: LGTM!

Also applies to: 14-14, 48-63


📝 Walkthrough

Walkthrough

The Search component now types its database state with AnyOrama. Its search effect uses synchronous result handling, skips promise results, maps up to eight hits, and clears hits on errors.

Changes

Search handling

Layer / File(s) Summary
Typed synchronous search execution
website/src/components/react/Search.tsx
The component imports AnyOrama, uses it for database state, and replaces the promise chain with try/catch handling. Promise results return early. Successful results map up to eight hits, and errors clear the hits.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to bb376

Search results are processed synchronously for this database configuration, and the change has no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the website search fix and the synchronous Orama v3 API issue.
Description check ✅ Passed The description directly explains the Orama v3 compatibility issue, the implemented fix, and the verification results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/website-search-orama-v3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread website/src/components/react/Search.tsx Outdated
term: query,
properties: ['title', 'description', 'content'],
});
if (res instanceof Promise) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: The instanceof Promise guard silently discards results on the async path. If search() ever returns a real Promise (Orama v2, plugin mode, or a future v3 change), this branch returns without awaiting and without updating hits, leaving stale results visible and offering no error feedback. The previous .then().catch() chain correctly handled that case.

Additionally, instanceof Promise is unreliable across realms (iframes, certain bundler split-chunks, polyfilled globals): a real Promise from another realm would not satisfy the check and would proceed into setHits((res.hits ?? []) where res.hits is undefined, then be silently swallowed by ?? [] and produce zero hits.

Safer pattern that handles both shapes:

Suggested change
if (res instanceof Promise) return;
const apply = (res: any) =>
setHits(
(res?.hits ?? []).slice(0, 8).map((h: any) => ({
url: h.document.url,
title: h.document.title,
description: h.document.description,
})),
);
const result = search(db, {
term: query,
properties: ['title', 'description', 'content'],
});
Promise.resolve(result).then(apply);

Combined with the existing try/catch (and adding a .catch(setEmpty) on the chain), this works for sync v3, async v2, and any future change without dropping results.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The previous WARNING (the instanceof Promise guard silently discarding async results) is fully resolved by the new commit. The replacement uses Promise.resolve(...).then(apply) to handle both sync (v3) and async (v2/future) shapes, adds a per-effect cancelled flag with cleanup so stale responses cannot overwrite newer hits, and keeps the existing try/catch for synchronous throws from search(). The @orama/orama floor bump to ^3.1.18 is consistent with the locked/tested version.

Files Reviewed (2 files)
  • website/src/components/react/Search.tsx
  • website/package.json
Previous Review Summary (commit bb376c3)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit bb376c3)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
website/src/components/react/Search.tsx 53 instanceof Promise guard silently discards async results and is unreliable across realms; sync v3 works, but any async return (v2, plugin mode, future change, cross-realm Promise) produces zero hits with no signal.
Files Reviewed (1 file)
  • website/src/components/react/Search.tsx - 1 issue

Fix these issues in Kilo Cloud


Reviewed by minimax-m3 · Input: 0 · Output: 0 · Cached: 0

Replace the instanceof Promise guard, which silently dropped results on
any async path and is unreliable across realms, with a
Promise.resolve(...).then(apply) chain that handles both sync (v3) and
async (v2) shapes. Add a cancelled flag so stale async responses from a
previous query cannot overwrite newer results. Bump @orama/orama floor
to ^3.1.18, the version already locked and tested.
@IamCoder18

Copy link
Copy Markdown
Owner Author

Review addressed in c97ae6a: replaced the instanceof Promise guard with Promise.resolve(search(...)).then(apply) so both sync (v3) and async (v2/cross-realm) result shapes are handled, added a .catch on the chain and a cancelled flag so stale async responses can't overwrite newer results. Also bumped the @orama/orama floor to ^3.1.18 (already the locked and latest published version).

@IamCoder18
IamCoder18 merged commit 285d210 into main Sep 13, 2026
5 checks 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.

1 participant