fix: prevent glitch in default transport with a "connecting" state#1359
Merged
Conversation
chakra-guy
approved these changes
Oct 3, 2025
6d550e0 to
97bd3a5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1359 +/- ##
==========================================
- Coverage 75.10% 74.99% -0.12%
==========================================
Files 184 184
Lines 4519 4519
Branches 1108 1108
==========================================
- Hits 3394 3389 -5
- Misses 1125 1130 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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.



Explanation
There is currently an issue in the multichain sdk, affecting the browser.
If the user clicks connect and has no extension installed the ShowInstall modal will display on screen.
When this happens, we automatically setup the Mobile Wallet protocol transport as used transport, the glitch happens if the user clicks refresh screen without closing the install modal. If that happens, we will have stored MWP as default transport when we have no proof this is the transport the user wants.
Upon the screen refresh it automatically tries to connect to MWP but it has nothing to connect into, because connection never succeeded.
This buggy behavior is fixed by listening to window.addEventListener('beforeunload') event and removing the transport if the modal is still visible.
References
Checklist
Note
Adds a beforeunload handler to remove stored transport when the install modal is open and manages its lifecycle to prevent stale connections and leaks.
packages/sdk-multichain/src/multichain/index.ts):onBeforeUnloadto remove stored transport if the install modal is visible.beforeunloadlistener management:createBeforeUnloadListenerregisters/unregisters the handler; stored in__beforeUnloadListener.showInstallModaland disposed indisconnect.disconnectnow invokes and clears thebeforeunloadlistener before tearing down transport and state.Written by Cursor Bugbot for commit 97bd3a5. This will update automatically on new commits. Configure here.