fix: preserve instance-scoped event listeners on disconnect and fix beforeunload listener leak#170
Open
chakra-guy wants to merge 3 commits intomainfrom
Open
fix: preserve instance-scoped event listeners on disconnect and fix beforeunload listener leak#170chakra-guy wants to merge 3 commits intomainfrom
chakra-guy wants to merge 3 commits intomainfrom
Conversation
…nload listener leak - Stop removing `display_uri` and `wallet_sessionChanged` listeners in `MetamaskConnectEVM.disconnect()`. These are instance-scoped listeners registered once in the constructor and never re-registered, so removing them broke reconnection in headless mode (QR code URI and session updates stopped firing after disconnect+reconnect). - Fix `#createBeforeUnloadListener()` in `MetaMaskConnectMultichain` to store the bound handler reference and reuse it for both addEventListener and removeEventListener. Previously, `.bind()` was called separately for each, creating different function references, so the listener was never actually removed (memory leak on each connect/disconnect cycle).
wenfix
previously approved these changes
Feb 6, 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
display_uri/wallet_sessionChangednot firing on reconnect:MetamaskConnectEVM.disconnect()was removing thedisplay_uriandwallet_sessionChangedlisteners from the core instance, butconnect()never re-registered them. After a disconnect→reconnect cycle (especially in headless mode), the QR code URI was never emitted and session scope updates were silently lost. Fix: stop removing these instance-scoped listeners on disconnect — they should live for the lifetime of the SDK instance. Session-scoped listeners (notification handler) are still correctly cleaned up.beforeunloadlistener never actually removed (memory leak):#createBeforeUnloadListener()called.bind(this)separately inaddEventListenerandremoveEventListener, producing two different function references. SinceremoveEventListenerrequires the exact same reference, the cleanup was silently a no-op, leaking a listener on every connect/disconnect cycle. Fix: store the bound function once and reuse it.References
Checklist