Skip to content

Conversation

@tomusdrw
Copy link
Member

Resolves #40

@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

The changes convert native binding loading from a synchronous, static initialization pattern to an asynchronous loader function. The loadNativeBinding() function now dynamically imports createRequire to support non-Node.js environments, removing pre-bound function exports and requiring consumers to explicitly call the loader and access methods from the returned object.

Changes

Cohort / File(s) Summary
Native Binding Initialization
bandersnatch/src/native.ts
Replaced static native binding initialization with async loadNativeBinding() function using dynamic import. Removed all exported binding wrapper constants (ringCommitment, derivePublicKey, verifyHeaderSeals, verifySeal, generateSeal, vrfOutputHash, batchGenerateRingVrf, batchVerifyTickets). Public API now requires calling loadNativeBinding(): Promise<NativeBinding> to access binding methods.
Entry Point Integration
bandersnatch/src/index.ts
Updated to invoke native.loadNativeBinding() after dynamic import instead of accessing native.default or native object directly, aligning with the new async loader pattern.

Sequence Diagram(s)

sequenceDiagram
    participant Consumer as Consumer Code
    participant Index as index.ts
    participant Native as native.ts
    participant DynamicImport as Dynamic Import
    participant Module as Node Module
    
    Consumer->>Index: loadNativeBinding()
    Index->>Native: dynamic import native.ts
    activate Native
    Native->>DynamicImport: dynamic import('module')
    DynamicImport->>Module: get createRequire
    Module-->>Native: createRequire function
    Native->>Native: construct require()
    Native->>DynamicImport: dynamic import(nativeBindingPath)
    DynamicImport-->>Native: NativeBinding
    Native-->>Index: Promise<NativeBinding>
    deactivate Native
    Index-->>Consumer: NativeBinding
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • Native bandersnatch bindings #30: Introduced the native bandersnatch bindings that this PR refactors from synchronous to asynchronous loading with dynamic imports.

Suggested reviewers

  • mateuszsikora
  • DrEverr
🚥 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%. 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 and concisely describes the main change: converting eager native binding loading to lazy loading.
Description check ✅ Passed The description references issue #40, which is directly related to the changeset's objective of lazy loading native bindings.
Linked Issues check ✅ Passed The PR implements lazy loading of native bindings by deferring import and creation until loadNativeBinding() is called, which addresses the core requirement to prevent eager loading in browser environments.
Out of Scope Changes check ✅ Passed The changes are focused on refactoring the native binding loading mechanism to be lazy; all modifications are directly related to the linked issue's objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch td-lazy-native

No actionable comments were generated in the recent review. 🎉


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 and usage tips.

@mateuszsikora mateuszsikora merged commit e2a2c06 into main Feb 10, 2026
4 checks passed
@mateuszsikora mateuszsikora deleted the td-lazy-native branch February 10, 2026 17:31
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.

createRequire from module does not work in browser

2 participants