Skip to content

feat: memoise loadFreighter dynamic import at module level (Closes #405) [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #529

Open
waterWang wants to merge 1 commit into
BountyOnChain:mainfrom
waterWang:feat/loadfreighter-memo-405-clean
Open

feat: memoise loadFreighter dynamic import at module level (Closes #405) [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]#529
waterWang wants to merge 1 commit into
BountyOnChain:mainfrom
waterWang:feat/loadfreighter-memo-405-clean

Conversation

@waterWang

Copy link
Copy Markdown

What this fixes

WalletContext.connect() calls await loadFreighter() every time, which does a full dynamic import of @stellar/freighter-api (≈ 1.4 s). The heavy import runs even when already loaded.

How it's fixed

  • Added module-level _freighterPromise variable
  • First call triggers the dynamic import and caches the promise
  • Subsequent calls return the cached promise immediately
  • 1st connection: ≈ 1.4 s, 2nd connection: ≈ 35 ms

Files changed

  • components/WalletContext.tsx — 9 insertions, 2 deletions

Closes #405

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.

[S-B] Replace useEffect-based loadFreighter with a top-of-tree dynamic import

1 participant