fix(db): lazily initialize runtime reference identities - #1782
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe runtime reference identity factory now initializes on first use instead of during module evaluation. A test verifies that import does not access random values and that repeated calls initialize the identity source once. A patch changeset documents the update. ChangesRuntime reference identity lifecycle
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change defers runtime identity initialization until first use while preserving cached identity behavior; no actionable merge-blocking risk remains after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant ModuleEvaluation
participant getRuntimeReferenceIdentity
participant crypto
ModuleEvaluation->>getRuntimeReferenceIdentity: Import module without invoking function
getRuntimeReferenceIdentity->>crypto: Call getRandomValues on first invocation
getRuntimeReferenceIdentity->>getRuntimeReferenceIdentity: Cache identity factory
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description includes the required Changes, Checklist, and Release Impact sections. It explains the motivation, testing, production verification, and changeset, with the required checklist items marked. Full details: Linked Issues checkExplanation The implementation addresses issue
✨ Finishing Touches🧪 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 |
🎯 Changes
Lazily initializes runtime reference identities when they are first needed instead of during module evaluation.
The previous eager initialization called
crypto.getRandomValues()at global scope, causing@tanstack/dbimports to fail in Cloudflare Workers before the request handler could run.The initialized factory remains cached for the lifetime of the runtime, preserving the existing namespace,
WeakMap, and reference identity semantics.This PR also adds:
getRandomValues.@tanstack/db.The fix was additionally verified in a production Cloudflare Worker.
✅ Checklist
pnpm test.🚀 Release Impact
This fixes #1781
Summary by CodeRabbit
Bug Fixes
Tests