fix(orama): break the search circular dependency behind Metro/Expo failure (#961)#1026
Merged
Conversation
methods/search.ts held both the search() dispatcher (which imports the per-mode search modules) and the fetchDocuments/fetchDocumentsWithDistinct helpers those same modules import back — a circular dependency. Harmless under most bundlers, but fatal under Metro/Expo with experimentalImportSupport (tree-shaking), where it surfaces as 'fetchDocuments is not a function' (#961). Extract the two helpers into methods/fetch-documents.ts and import them from there in search-fulltext.ts / search-hybrid.ts. search.ts no longer has a back-edge, so the cycle is eliminated for every bundler — no extra build step or shipped bundle artifact. Pure code move, no behavioral change (1326 orama tests pass). Addresses #961. Supersedes #963, which worked around the cycle with an esbuild bundle.
This was referenced Jun 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root-cause fix for #961 (
fetchDocuments is not a functionunder Metro/Expo). Supersedes #963, which worked around the same cycle by shipping an esbuild-bundled artifact.The bug
methods/search.tswas overloaded — it held both:search()dispatcher, which importsfullTextSearch/searchVector/hybridSearch, andfetchDocuments/fetchDocumentsWithDistincthelpers, which those same per-mode modules import back.That mutual import (
search.ts ⇄ search-fulltext.ts,search.ts ⇄ search-hybrid.ts) is a circular dependency. It's harmless under Node and most bundlers, but fatal under Metro/Expo withexperimentalImportSupport(the new tree-shaking), where the binding is read before initialization →fetchDocuments is not a function.The fix
Move the two pure helpers into a new
methods/fetch-documents.ts(they depend only oninternal-document-id-store+getNested— no back-edge), and import them from there insearch-fulltext.ts/search-hybrid.ts.search.tskeeps only the dispatcher.search-fulltext/search-hybridno longer importsearch.ts→ the cycle is gone.bundleexport condition, no second artifact, no esbuild added to the build.Why this instead of #963
#963 (the maintainer's own suggestion) fixes the symptom by adding a
bundleexport condition + an esbuildpostbuildthat ships pre-bundleddist/bundle/*. It works, but: consumers must configure their resolver to prefer thebundlecondition, it ships a parallel minified copy of the library, adds esbuild to the core build, and masks cycles rather than removing them. This PR removes the cycle at the source instead.Validation
pnpm build— 18/18 packages green.pnpm --filter @orama/orama test— 1326 pass / 0 fail / 3 skip (40/40 suites). Pure code move, no behavior change.fetchDocuments/fetchDocumentsWithDistinctwere never exported (onlysearchis).Verification still needed
This removes the specific cycle behind the reported error. @isaachinman — you have the Metro/Expo repro (
orama-require-cycle-reproduction) and kindly offered to verify; could you confirmbun run webis clean against this branch? If Metro surfaces a second cycle once this one's gone, I'll extract that too. Keeping #963 open as a fallback until the repro confirms.Addresses #961.