Skip to content

Feature/wallet context memory leak#283

Merged
gabito1451 merged 6 commits into
NOVUS-X:mainfrom
AugistineCreates:feature/wallet-context-memory-leak
Apr 28, 2026
Merged

Feature/wallet context memory leak#283
gabito1451 merged 6 commits into
NOVUS-X:mainfrom
AugistineCreates:feature/wallet-context-memory-leak

Conversation

@AugistineCreates
Copy link
Copy Markdown
Contributor

This pr closes #233

This PR addresses performance issues within WalletContext.tsx caused by redundant initializations and improper event listener cleanup. Previously, the component could instantiate multiple overlapping StellarWalletsKit instances across remounts (especially noticeable in React 18 Strict Mode or during hot reloading), which led to memory leaks.

Changes Included:

  • Controlled Instantiation: Introduced useRef to store the active kitRef instance. The dynamic import logic now correctly short-circuits if the kit has already been initialized, preventing duplicate network module loads.
  • Race Condition Prevention: Implemented an isMounted flag within the useEffect closure to prevent state updates on an unmounted context wrapper.
  • Listener Cleanup: Added a useEffect cleanup return block to safely invoke wallet event listener cleanup via removeEventListeners() or disconnect() on unmount, fully preventing stale listeners from degrading performance.
  • Verified Memoization: Audited useMemo configurations to ensure the provider correctly caches the state value connect/disconnect/signTransaction functions strictly based on their address and kit dependencies without causing unnecessary component re-renders.

@gabito1451 gabito1451 merged commit 7357ffe into NOVUS-X:main Apr 28, 2026
4 checks passed
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.

Frontend: Fix Memory Leaks in WalletContext

2 participants