fix(website): handle synchronous Orama v3 search API in docs search - #18
Conversation
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.
|
Warning Review limit reachedNext included review available in 49 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (1)
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)
🔇 Additional comments (1)
📝 WalkthroughWalkthroughThe ChangesSearch handling
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
| term: query, | ||
| properties: ['title', 'description', 'content'], | ||
| }); | ||
| if (res instanceof Promise) return; |
There was a problem hiding this comment.
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:
| 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.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The previous WARNING (the Files Reviewed (2 files)
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
Issue Details (click to expand)WARNING
Files Reviewed (1 file)
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.
|
Review addressed in c97ae6a: replaced the |
Summary
Uncaught TypeError: Dr(...).then is not a functionin the docs search dialog (⌘K)Orama v3 (3.1.18) returns
search()results synchronously in the browser, butSearch.tsxwas 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
search()directly and read the result, with aninstanceof Promiseguard so either API shape worksdbstate asAnyOrama(the previousAwaited<ReturnType<typeof create>>triggered TS2589 with v3 generics)Verification
tsc --noEmitclean (pre-existingastro.config.mjserror unrelated)astro buildsucceeds; new bundle calls search synchronouslydist/search.json: sync results, hits returned forSafeOpMode